EnduroDave
EnduroDave

Reputation: 1033

Why isn't my database filter working with google datastore?

The code below works but if I un-comment the 5th line I get an error

public void listByKindandFilterById(String kindName, String sortPropertyName, com.google.cloud.backend.core.CloudQuery.Order order,
                       int limit, Scope scope, CloudCallbackHandler<List<CloudEntity>> handler, String Id) {

    Log.d(TAG, Id); // I am definitely getting what I expect and whats in the db
    CloudQuery cq = new CloudQuery(kindName);
    //cq.setFilter(Filter.eq("rideid", Id));
    cq.setSort(sortPropertyName, order);
    cq.setLimit(limit);
    cq.setScope(scope);
    this.list(cq, handler);
}

I am new to datastore and just want to recreate the WHERE clause in SQL i.e. SELECT * kindName WHERE rideid = Id

What am I doing wrong?

Here is the error I get when I un-comment the line:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 503 Service Unavailable
{
"code": 503,
"errors": [
{
"domain": "global",
"message": "com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.\nThe suggested index for this query is:\n    <datastore-index kind=\"Ridemessage\" ancestor=\"false\" source=\"manual\">\n        <property name=\"rideid\" direction=\"asc\"/>\n        <property name=\"_createdAt\" direction=\"desc\"/>\n    </datastore-index>\n\n",
"reason": "backendError"
}
],
"message": "com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found.\nThe suggested index for this query is:\n    <datastore-index kind=\"Ridemessage\" ancestor=\"false\" source=\"manual\">\n        <property name=\"rideid\" direction=\"asc\"/>\n        <property name=\"_createdAt\" direction=\"desc\"/>\n    </datastore-index>\n\n"
}    

Upvotes: 0

Views: 171

Answers (1)

Patrice
Patrice

Reputation: 4692

The datastore needs an index to be able to serve a query. You can look at this document to better understand how they work.

Basically, I would suggest, to solve your problem, to push your code to your devserver, and make sure you run THAT query on your devserver. That will update your datastore-indexes.xml, and when you update your application, make sure to run "update indexes". It should work fine. I already explained a similar problem here

Upvotes: 2

Related Questions