No matching index found even Google Cloud show them - google-cloud-platform

I am trying to execute the following query:
SELECT google_uid FROM User WHERE api_key = #api_key
But I get the error:
no matching index found. recommended index is:\n- kind: User\n
properties:\n - name: api_key\n - name: google_uid\n
Here is the index configuration from Google:
I uploaded it yesterday, so I am sure Google have had time to update it on their side.
Any idea how to solve it?
Thanks

The properties in the index are ordered. So you have an index of (google_uid, api_key), but you don't have an index of (api_key, google_uid). This query requires a composite index of (api_key, google_uid) .
You can see this if you run the querySELECT data_clicked from User where api_key = #api_key . That will work since you have an index where api_key is the first property.

Related

Query Logs for filter non-empty strings in Google Cloud Logs Explorer

I am trying to query for all logs that meets a simple condition:
The jsonPayload of some DEFAULT log entries have the following structure:
response: {
Values: [
[ ]
]
}
where each item in Values is an array. In most cases, Values have a single item "" in the array (empty). I want to write a query that can filter all logs entry that have values different from an empty string (an array in fact).
Here's the query I tried to run:
severity="DEFAULT" AND
jsonPayload.response.Values != ''
This did not return any result. There are thousands of entries, most of which are empty. Can this be done? If so, what am I missing in this case?
Edit
I am checking to see if the first value inside Values is something other than an empty string. In entries I am looking for, the value of the first item will be an array.
Edit 2
Following the reference suggested, I tried looking for the opposite:
severity="DEFAULT" AND
jsonPayload.response.Values = ''
This shows me the all the results with empty Values array as expected. What's confusing me is why it's not working. The logs are generated by a cloud function that serves as a webhook for event processing. The jsonPayload represents the body of the request from the event source.
To filter non-empty strings in Google Cloud Logs Explorer as seen in the official documentation:
severity="DEFAULT" AND
jsonPayload.response.Values !~ ''
Another way would be:
severity="DEFAULT" AND
jsonPayload.response.Values:*
NOT jsonPayload.response.Values = ''

NeedIndexError in Google App Engine, despite indexes being served

I have uploaded my index.yaml file using the command line SDK:
Unfortunately I now have some of my entities indexed twice (but they are all serving):
But I am still getting a "Need Index Error" on running the page:
NeedIndexError: no matching index found. recommended index is:
- kind: RouteDetails
ancestor: yes
properties:
- name: RouteName
direction: desc
The suggested index for this query is:
- kind: RouteDetails
ancestor: yes
properties:
- name: RouteName
direction: desc
How can I get Google App Engine to recognise my entity's index?
And how do I delete the duplicates? (Do I need to?)
Datastore requires explicit indexes to be created for each query type when the query scans over more than one property or is an ancestor query. And kinds will certainly be indexed more than once if you have different query types.
For example:
SELECT * FROM RouteDetails
WHERE __key__ HAS ANCESTOR KEY(ParentKind, 'foo')
ORDER BY RouteName ASC
requires an ascending index.
- kind: RouteDetails
ancestor: yes
properties:
- name: RouteName
direction: asc
And
SELECT * FROM RouteDetails
WHERE __key__ HAS ANCESTOR KEY(ParentKind, 'foo')
ORDER BY RouteName DESC
requires a separate descending index.
- kind: RouteDetails
ancestor: yes
properties:
- name: RouteName
direction: desc
https://cloud.google.com/datastore/docs/concepts/indexes
In your case, it appears you are performing an ancestor query with a descending ORDER BY of the RouteName property and adding the suggested index to your index.yaml file should solve the problem for you.
As for the suspected "duplicates", which indexes need to exist depend on the specific queries your application performs.
But if you determine that you have extra unused indexes, the instructions for vacuuming indexes can be found here: https://cloud.google.com/datastore/docs/tools/indexconfig#Datastore_Deleting_unused_indexes
The index includes the order by direction - you can see the up arrows in the console view indicating all fields ascending.
The suggested index is a descending index on one of the properties.
Your 'duplicate' indexes have been introduced by the reason field, which you indexed as both capital r and lower case r, which are different named fields
Just in case anyone else stumbles across this question and is having a similar problem.
The reason it was looking for an index with ancestor: yes is that I was using the wrong query, and it should not have had an ancestor key in it at all.
Here is my new query:
class RouteDetails(ndb.Model):
"""Get list of routes from Datastore """
RouteName = ndb.StringProperty()
#classmethod
def query_routes(cls):
return cls.query().order(-cls.RouteName)
class RoutesPage(webapp2.RequestHandler):
def get(self):
adminLink = authenticate.get_adminlink()
authMessage = authenticate.get_authmessage()
self.output_routes(authMessage,adminLink)
def output_routes(self,authMessage,adminLink):
self.response.headers['Content-Type'] = 'text/html'
html = templates.base
html = html.replace('#title#', templates.routes_title)
html = html.replace('#authmessage#', authMessage)
html = html.replace('#adminlink#', adminLink)
self.response.out.write(html + '<ul>')
list_name = self.request.get('list_name')
#version_key = ndb.Key("List of routes", list_name or "*notitle*")
routes = RouteDetails.query_routes().fetch(20)
for route in routes:
self.response.out.write('<li>%s</li>' % route)
self.response.out.write('</ul>' + templates.footer)
I was using this page of the documentation, which doesn't tell you how to construct a query for a kind with no ancestor.
https://cloud.google.com/appengine/docs/standard/python/datastore/queries

Datastore: composite index not recognised

I've written a piece of code that adds and retrieves entities from the Datastore based on one filter (and order on the same property) - that worked fine. But when I tried adding filters for more properties, I got:
PreconditionFailed: 412 no matching index found. recommended index is:- kind: Temperature properties: - name: DeviceID - name: created
Eventually I figured out that I need to create index.yaml. Mine looks like this:
indexes:
- kind: Temperature
ancestor: no
properties:
- name: ID
- name: created
- name: Value
And it seems to be recognised, as the console shows:
that it has been updated
Yet when I run my code (specifically this part with two properties), it doesn't work (still getting the above-mentioned error) (the code is running on the Compute Engine).
query.add_filter('created', '>=', newStart)
query.add_filter('created', '<', newEnd)
query.add_filter('DeviceID', '=', devID)
query.order = ['created']
Trying to run the same query on the console produces
Your Datastore does not have the composite index (developer-supplied) required for this query.
error. Search showed one other person who had the same issue and he managed to fix it by changing the order of the properties in the index.yaml, but that is not helping in my case. Has anybody encountered a similar problem or could help me with the solution?
You'll need to create the exact index suggested in the error message:
- kind: Temperature
ancestor: no
properties:
- name: DeviceID
- name: created
Specifically, the first property in the index needs to be DeviceID instead of ID and the last property in the index needs to be the one you're using in the inequality filter (so you can't have Value as the last property in the index).

Special characters in sitecore item name (*)

It is possible to create an item with *** name in sitecore.
this would allow to process any page name.
What would be if create * item, and one more (*) like a child item ?
What would be if create * item under bucket item ?
You can create an item called * in Sitecore. Lets assume that your content tree is:
-home
- item-a
- item-b
- item-c
- *
- *
- item-d
- *
If you hit url:
/ - home item is returned
/item-a - item-a item is displayed
/item-b/item-c - item-c is displayed
/item-b/something-else - /item-b/* iten is displayed
/aaa - * item is displayed
/bbb/ccc - */* item is displayed.
So if there is an item at given level with a name which matches url segment, this item will be used. In other case, Sitecore will check if there is a wildcard item (item with name *), and will continue with matching the next segment.
I've never tried with wildcard items in bucket - I don't think it make much sense there.
Marek is right in his explanation (below). I would want to add couple more concerns to think about:
How would you make it Page Editor friendly?
How would address and resolve datasources (by URL? on the fly?). You have just one page item that handles all the matching page requests for multiple datasources.
How would you get Page Not Found (proper 404 status code) support, in case you do not have a datasource?
All that should be taken into consideration before you start implementation.
I wrote an article in attempt to answer those questions. Please read at:
http://blog.martinmiles.net/post/wildcard-items-pages-with-mvc-passing-the-correct-datasources-based-on-requested-item-url
Hope that helps.

Connect to LDAP via ColdFusion

I am trying to get the following connection to our LDAP working via ColdFusion, however, I can never get it to return any values (i.e. results.recordcount always equals 0). I assume my problem is with the "start" portion of the query so I did some research and have tried numerous values but nothing seems to work.
<cfldap
server = "adserver"
action = "query"
username = "DOMAIN\username"
password = "apassword"
name = "results"
scope="subtree"
start = "dc=domain.local"
attributes = "givenname,surname,uid,userid,groupMembership,mail,dn,roles,memberof,cn,samaccountName">
<cfoutput>
#results.recordcount#
</cfoutput>
The structure of the AD that I'm trying to access is as follows. I'm trying to get to the "Users" section at the bottom of the tree shown.
Active Directory Users and Computers
- Saved queries
- domain.local
- option1
- option2
- NAME1
- option1
- option2
- NAME2
- Computers
- Disabled Users
- Groups
- Users
If I right-click on "User" and view the properties it tells me the canonical name for it is domain.local/NAME1/NAME2/Users, which I assume is relevant to my problem.
Any ideas what I should be using for the "start" portion of cfldap?
Thanks in advance.
I highly recommend browsing your AD with a program like Softerra's LDAP Browser (http://www.ldapbrowser.com/) and then locating the distinguished name of the hierarchy where you want to start searching. Using this, I was able to find the exact DN of the LDAP structure to target.
Try somethign like this. I've had the best luck starting at a high level and then using the filter attribute to drill down.
<cfldap action="query" start="DC=server, DC=domain, DC=com" filter="OU=Users"
username = "DOMAIN\username" password = "apassword" name = "results"
scope="subtree" attributes = "givenname,surname,uid,userid,groupMembership,mail,dn,roles,memberof,cn,samaccountName">