Reputation: 15
I have created a Kind called User in Google App Engine datastore, and I am trying to add an index for this kind.
Firstly, I followed https://cloud.google.com/appengine/docs/standard/java/config/indexconfig to create index by adding datastore-indexes.xml inside war/WEB-INF, but it doesn't work, no index is created after I deploy to app engine.
Then I followed https://cloud.google.com/appengine/docs/standard/python/config/indexref, I created a index.yaml and run gcloud app deploy index.yaml
, this time I can see the index created in GCP console as seen below.
But I still got an exception as below:
Uncaught exception from servlet
com.google.appengine.api.datastore.DatastoreNeedIndexException:
no matching index found. recommended index is:
- kind: User
properties:
- name: area
- name: coins_balance
The suggested index for this query is:
<datastore-index kind="User" ancestor="false" source="manual">
<property name="area" direction="asc"/>
<property name="coins_balance" direction="asc"/>
</datastore-index>
I searched google with "index created but still got DatastoreNeedIndexException", but didn't find any helpful information.
Please can someone help, thanks.
Upvotes: 1
Views: 248
Reputation: 2887
The order of the properties in the index matters. The screenshot shows an index for
- kind: User
properties:
- name: coins_balance
- name: area
You actually want:
- kind: User
properties:
- name: area
- name: coins_balance
So you can either change your query to match your existing index, or you can build the index that the recommended index.
Upvotes: 0