Google 数据存储综合索引问题

Google Datastore Composite index issue

我遇到异常:

Exception in thread "main" com.google.cloud.datastore.DatastoreException: no matching index found. recommended index is:
- kind: cp_outbox
  properties:
  - name: format
  - name: occasion_name
  - name: sent_datetime
  - name: status
  - name: send_date

虽然 运行 下面查询:

SELECT * FROM cp_outbox where send_date <= '2018-03-14' and sent_datetime is null and format='test1' and status=0 and occasion_name='test'

所以我在查询中使用了不等运算符并且我有复合索引:

但我仍然遇到异常。

通过查看错误,我认为属性的排序是问题所在。如果这是真的那么为什么这个顺序很重要。

提前致谢。

属性 在为查询提供服务时,顺序对于复合索引绝对重要。该顺序使我们能够提供范围查询,而无需扫描索引的大部分 table。作为一般规则,最后的 属性 是您可以对其进行不等式查询的内容,然后重命名 属性 顺序定义了您可以使用的 order by 子句顺序。

在您的查询中,send_date 是您正在做的不平等,而您现有的复合索引只允许 occasion_name

如果您完全按照 API 返回的方式创建复合索引,您的查询将起作用。