【问题标题】:Google App Engine Guestbook example index not workingGoogle App Engine 留言簿示例索引不起作用
【发布时间】:2017-10-02 20:49:18
【问题描述】:

我查看了 Google 的留言簿代码示例。它在本地构建,我可以将它部署到我的本地机器上,并且运行正常。

当我尝试将其部署到 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)

经过一番谷歌搜索后,我发现有人提出了两件事之一。 1) 在 YAML 中进行一些编辑。 2)手动修改TARGET并添加一些索引配置。

我想避免这两种情况,因为 1) 在最新的留言簿代码示例中没有 YAML 并且 2) 我更喜欢自动构建而不是每次我想部署时手动破解它。

在使用 mvn appengine:deploy 时有什么方法可以使这项工作?

这是我一直在使用的指南:https://cloud.google.com/appengine/docs/standard/java/tools/using-maven

【问题讨论】:

    标签: java maven google-app-engine


    【解决方案1】:

    根据应用的具体使用情况手动修改数据存储索引配置文件是完全正常的(有时甚至需要)。示例代码中可能缺少此类文件的原因可能是它通常是自动生成的。来自Cloud Datastore Indexes

    重要提示:有关索引和查询的深入讨论,请参阅文章Index Selection and Advanced Search

    App Engine 为实体的每个属性预定义了一个简单的索引。一个 App Engine 应用程序可以在名为 datastore-indexes.xmlindex configuration file 中定义更多自定义索引,即 在您的应用程序的/war/WEB-INF/appengine-generated 中生成 目录 。开发服务器自动将建议添加到 此文件遇到无法使用 现有的索引。您可以通过编辑文件手动调整索引 在上传应用程序之前。

    您还应该注意,数据存储索引配置是应用级别的配置,由所有应用的服务/模块共享,即使它们不是用 Java 编写的。这就是为什么您可能会看到对datastore-indexes.xml(仅限java,您的消息中建议的索引格式适用于此文件)和index.yaml(所有语言)的引用。

    另一个重要的注意事项是索引配置可以独立于服务/模块代码进行部署,包括使用 maven。来自App Engine Maven Plugin Goals and Parameters

    appengine:deployIndex

    index.yaml 配置文件部署到 App Engine。

    因此,只需使用此目标来更新您的数据存储索引配置。

    【讨论】:

      猜你喜欢
      • 2011-03-07
      • 1970-01-01
      • 2017-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      • 2014-11-26
      • 1970-01-01
      相关资源
      最近更新 更多