Google Datastore error: No matching index found

Google Datastore error: No matching index found

我想测试我在 Google 数据存储中创建的新实体。我正在尝试使用不等式执行 GQL 查询以检索数据存储 Web 界面中的一些实体:

SELECT * FROM UserMatchingIndex WHERE age < 25 AND wants_male = false AND wants_dating = false AND wants_friendship = false AND wants_age = 20

但我总是遇到错误:“GQL 查询错误:您的数据存储没有此查询所需的复合索引(开发人员提供)。”而我已经定义了所需的复合索引!

UserMatchingIndex: age ▲ wants_male ▲ wants_dating ▲ wants_friendship ▲ wants_age ▲ Serving

UserMatchingIndex: age ▲ wants_female ▲ wants_dating ▲ wants_friendship ▲ wants_age ▲ Serving

这些定义如下 index.yaml:

- kind: UserMatchingIndex
  ancestor: no
  properties:
  - name: age
  - name: wants_male
  - name: wants_dating
  - name: wants_friendship
  - name: wants_age

- kind: UserMatchingIndex
  ancestor: no
  properties:
  - name: age
  - name: wants_female
  - name: wants_dating
  - name: wants_friendship
  - name: wants_age

我真的看不出可能有什么问题...我已经为其他实体做过很多次了。如果你有什么线索,不客气。

此问题已提交给 Google 云支持,这似乎是他们方面的问题,或者至少是尚未记录的限制。更改属性的顺序如下:

- kind: UserMatchingIndex
  ancestor: no
  properties:
  - name: wants_male
  - name: wants_dating
  - name: wants_friendship
  - name: wants_age
  - name: age

使查询有效。

编辑:来自Google支持

的回答

"The rows of an index table are sorted first by ancestor and then by property values, in the order specified in the index definition. The perfect index for a query, which allows the query to be executed most efficiently, is defined on the following properties, in order:

  1. Properties used in equality filters
  2. Property used in an inequality filter (of which there can be no more than one)
  3. Properties used in sort orders

This ensures that all results for every possible execution of the query appear in consecutive rows of the table."

应该尽快记录此限制。