Google App Engine 数据存储区索引已创建但仍出现 DatastoreNeedIndexException

Google App Engine datastore index created but still got DatastoreNeedIndexException

我在 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>

我用 "index created but still got DatastoreNeedIndexException" 搜索了 google,但没有找到任何有用的信息。

请问有人能帮忙吗,谢谢。

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

因此您可以更改查询以匹配现有索引,也可以构建推荐索引的索引。