Google Datastore Composite index issue

时间秒杀一切 提交于 2019-12-01 04:17:47

问题


I am getting below exception :

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

While running below query :

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'

So I am using inequality operator in query and I have composite index for that :

But still I am getting exception.

By looking at error I think the ordering of properties is the issue. If this is true then why this ordering is important.

Thanks in Advance.


回答1:


Property order absolutely matters for composite indexes when serving queries. The order is what allows us to serve range queries without having to scan through large sections of the index table. As a general rule, the final property is what you can do the inequality queries on, then the renaming property order defines the order by clause order you can use.

In your query send_date is what you are doing inequality on, whereas your existing composite index only allows for occasion_name.

If you create the composite index exactly as the API has returned your query will work.



来源:https://stackoverflow.com/questions/49318996/google-datastore-composite-index-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!