jcollomosse jcollomosse - 1 year ago 89
Android Question

Viewing and Amending Google Datastore Indexes from Console

Is it possible to view and create an index on the Google Cloud Datastore for my project, using the Google Developer Console?

If not, how can I create one via another route?

Some context: I am writing a simple Android app to store/retrieve data from the cloud datastore by customising the "Mobile Backend Starter / MBS" (that backend we are always invited to deploy when creating a new project in the dev console).

I am now at the point where the queries / filters I am specifying in my Android client are returning a "503" error stating that an index is required. I think this is because I am using a "greater than" filter in my query.

So how can I add one? Or do I have to edit the backend deployment package to do this? If so, then how can I do this e.g. view the folder MBS backend got deployed to? I had assumed MBS was a zero configuration backend - we just need to write the client, but it seems even basic query ops need an index adding so this isn't the case? I am being suggested to add an xml fragment somewhere in the IOException thrown by the list() call I'm making to CloudBackend:

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=\"DB\" ancestor=\"false\" source=\"manual\">\n <property name=\"_createdBy\" direction=\"asc\"/>\n <property name=\"originatingDeviceID\" direction=\"asc\"/>\n <property name=\"LastUpdatedOn\" direction=\"asc\"/>\n </datastore-index>\n\n",
"reason": "backendError"

... SNIP

Answer Source

Thanks all for your input - for future reference here is the solution for users like me who just deploy the MBS and haven't/don't want to interact with the server-side code which should be just deploy and go.

First you download the currently deployed backend via the Google App Engine SDK tool:

 appcfg.cmd --application=my-project-name download_app .

Then in WEB-INF/datastore-indexes.xml we see the auto generation of the index has been disabled in the vanilla MBS configuration.

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes autoGenerate="false">
    <datastore-index kind="_CloudMessages" ancestor="false">
       <property name="topicId" direction="asc"/>
       <property name="_createdAt" direction="desc"/>

which is why my index was not getting built. You then paste in the recommended index which fortunately is included in the Java IOException message body, and upload it back to Google via:

 appcfg.cmd --application=my-project-name update_indexes .

It would have been super-useful for Google Console to have some dashboard capability to manage indexes much as it has to add/delete/edit Entities, but it seems you can only inspect them.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download