Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Datastore Composite index issue

Tags:

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 :

enter image description here

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.

like image 221
ganesh_patil Avatar asked Mar 16 '18 10:03

ganesh_patil


People also ask

What is index in Datastore?

Built-in indexes. By default, a Datastore mode database automatically predefines an index for each property of each entity kind. These single property indexes are suitable for simple types of queries. Composite indexes. Composite indexes index multiple property values per indexed entity.

How do I delete an index in Datastore?

Deleting unused indexes When you are sure that old indexes are no longer needed, you can delete them by using the datastore indexes cleanup command. This command deletes all indexes for the production Datastore mode instance that are not mentioned in the local version of index.

Is Datastore transactional?

A transaction is a set of Datastore operations on one or more entities in up to 25 entity groups. Each transaction is guaranteed to be atomic, which means that transactions are never partially applied. Either all of the operations in the transaction are applied, or none of them are applied.

What are complex indexes?

A composite index is a statistical tool that groups together many different equities, securities, or indexes in order to create a representation of overall market or sector performance. Typically, the elements of a composite index are combined in a standardized way so that large amounts of data can be presented easily.


1 Answers

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.

like image 70
Dan McGrath Avatar answered Nov 11 '22 02:11

Dan McGrath