简体   繁体   中英

Google App Engine Guestbook example index not working

I have checked out Googles code example for the Guestbook. It builds locally and I can deploy it to my local machine and it is working out ok.

When I try to deploy it to Google App Engine this happens in the log:

com.google.appengine.api.datastore.DatastoreNeedIndexException: no matching index found. recommended index is:
- kind: Greeting
  ancestor: yes
  properties:
  - name: date
    direction: desc

The suggested index for this query is:
    <datastore-index kind="Greeting" ancestor="true" source="manual">
        <property name="date" direction="desc"/>
    </datastore-index>


    at com.google.appengine.api.datastore.DatastoreApiHelper.translateError(DatastoreApiHelper.java:56)

After a bit of Googling I find people that suggest one of two things. 1) Do some editing in the YAML. 2) Manually modify the TARGET and add some index config.

I'd like to avoid both because 1) In the latest Guestbook code sample there is no YAML and 2) I prefer to automate my build than to manually hack it every time I want to deploy.

Is there any way to make this work when using mvn appengine:deploy ?

This is the guide I have been using : https://cloud.google.com/appengine/docs/standard/java/tools/using-maven

It's perfectly normal (sometimes even required ) to manually modify the datastore index configuration file according to your app's specific usage. The reason for which such file may be missing from the sample code could be that it is typically auto-generated. From Cloud Datastore Indexes :

Important: For an in-depth discussion of indexes and querying, see the article Index Selection and Advanced Search .

App Engine predefines a simple index on each property of an entity. An App Engine application can define further custom indexes in an index configuration file named datastore-indexes.xml , which is generated in your application's /war/WEB-INF/appengine-generated directory . The development server automatically adds suggestions to this file as it encounters queries that cannot be executed with the existing indexes. You can tune indexes manually by editing the file before uploading the application.

You should also note that the datastore index configuration is an app-level configuration, shared by all app's services/modules, even if they're not written in Java. Which is why you may see references to both datastore-indexes.xml (java-only, the suggested index format in your message is for this file) and index.yaml (all languages).

Another important note is that the index configuration can be deployed independently from the service/module code, including with maven. From App Engine Maven Plugin Goals and Parameters :

appengine:deployIndex

Deploys an index.yaml configuration file to App Engine.

So just use this target to update your datastore index configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM