简体   繁体   English

Google App Engine留言簿示例索引不起作用

[英]Google App Engine Guestbook example index not working

I have checked out Googles code example for the Guestbook. 我已经签出了Guestbook的Google代码示例。 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: 当我尝试将其部署到Google App Engine时,会在日志中发生:

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. 1)在YAML中进行一些编辑。 2) Manually modify the TARGET and add some index config. 2)手动修改TARGET并添加一些索引配置。

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. 我想避免两者都发生,因为1)在最新的Guestbook代码示例中没有YAML,并且2)我更喜欢自动构建,而不是每次想要部署时都手动对其进行破解。

Is there any way to make this work when using mvn appengine:deploy ? 使用mvn appengine:deploy时,有什么方法可以使它工作?

This is the guide I have been using : https://cloud.google.com/appengine/docs/standard/java/tools/using-maven 这是我一直在使用的指南: 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 : 来自Cloud Datastore索引

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. App Engine会为实体的每个属性预先定义一个简单的索引。 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 . App Engine应用程序可以在名为datastore-indexes.xml索引配置文件中定义其他自定义索引,该文件在应用程序的/war/WEB-INF/appengine-generated目录中/war/WEB-INF/appengine-generated 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. 您还应该注意,数据存储区索引配置是应用程序级配置,即使不是用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). 这就是为什么您可能同时看到对datastore-indexes.xml (仅Java,消息中建议的索引格式针对此文件)和index.yaml (所有语言)的index.yaml

Another important note is that the index configuration can be deployed independently from the service/module code, including with maven. 另一个重要说明是,索引配置可以独立于服务/模块代码进行部署,包括使用maven。 From App Engine Maven Plugin Goals and Parameters : 通过App Engine Maven插件的目标和参数

appengine:deployIndex AppEngine上:deployIndex

Deploys an index.yaml configuration file to App Engine. index.yaml配置文件部署到App Engine。

So just use this target to update your datastore index configuration. 因此,只需使用此目标来更新数据存储索引配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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