nodejs-datastore icon indicating copy to clipboard operation
nodejs-datastore copied to clipboard

Google Cloud Datastore Index not found even if it is set

Open Shruthi-Bharadwaj opened this issue 3 years ago • 0 comments

I have a kind named 'audit' and has many properties, however, I need to index only certain properties and in a specific order since I mostly query:

select DISTINCT ON (traceId) * from audit where tenantId='123'

When I try to run this in the GCP console it throws an error: GQL Query error: Your Datastore does not have the composite index (developer-supplied) required for this query.

I also tried running this from a node js application that uses @google-cloud/datastore package, and datastore throws error:

9 FAILED_PRECONDITION: no matching index found. recommended index is:
- kind: audit
  properties:
  - name: tenantId
  - name: traceId

The index.yaml is created using terraforms and the contents are:

indexes:
- kind: "audit"
  properties:
  - name: "tenantId"
  - name: "traceId"
# AUTOGENERATED
# This index.yaml is automatically updated whenever the Cloud Datastore
# emulator detects that a new type of query is run. If you want to manage the
# index.yaml file manually, remove the "# AUTOGENERATED" marker line above.
# If you want to manage some indexes manually, move them above the marker line.

With this index.yaml file the local datastore emulator works as expected.

In the GCP console, I see the index being set and is in serving status.

Shruthi-Bharadwaj avatar Jan 28 '22 10:01 Shruthi-Bharadwaj