已创建Google App Engine数据存储区索引,但仍收到DatastoreNeedIndexException

时间:2019-03-22 02:53:49

标签: google-app-engine google-cloud-datastore

我已经在Google App Engine数据存储区中创建了一个名为User的种类,并且我正在尝试为此类型添加索引。

首先,我跟随https://cloud.google.com/appengine/docs/standard/java/config/indexconfig通过在war / WEB-INF内添加datastore-indexes.xml来创建索引,但这是行不通的,部署到应用程序引擎后没有创建索引。

然后我跟随https://cloud.google.com/appengine/docs/standard/python/config/indexref,创建了index.yaml并运行gcloud app deploy index.yaml,这一次,我可以看到在GCP控制台中创建的索引,如下所示。

Index seen in GCP console

但是我仍然遇到如下异常:

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>

我在Google上搜索了“已创建索引,但仍然存在DatastoreNeedIndexException”,但找不到任何有用的信息。

请有人帮忙,谢谢。

1 个答案:

答案 0 :(得分:0)

属性在索引中的顺序很重要。屏幕截图显示了一个索引 - kind: User properties: - name: coins_balance - name: area 您实际上想要: - kind: User properties: - name: area - name: coins_balance

因此,您可以更改查询以使其与现有索引匹配,或者可以根据推荐索引来构建索引。