Datastore composite index not being recognized despite removing and recreating

So I'm using Datastore as my DB with the NodeJS client and I'm making an aggregate query. I have an index.yaml setup to support getting counts, sums and such that has worked up until now. 

I tried creating a composite index for one of my Kinds and accidentally misspelled the Kind in my index.yaml, but I reversed this, ran gcloud datastore indexes cleanup and then gcloud datastore indexes create.

The new composite index shows up in my Datastore Indexes tab in GCP but when I try to make the request to my Node service that makes this aggregate query, an error is raised, and I'm still prompted to create the composite index by adding it to index.yaml. (error: Error: 9 FAILED_PRECONDITION: no matching index found. recommended index is: ) To clarify, this is different than the error that tells me that the index is in the process of being created and this error still appears no matter how much time passes. 

Has anyone ran into this before? I'm at my wits end.

0 2 353
2 REPLIES 2

It's possible that the Datastore has not yet fully processed your gcloud datastore indexes cleanup and create commands. Although the new index appears in the UI, it might not be fully operational for queries.

Here are some troubleshooting tips:

  1. Patience with Index Processing:

    • Index creation in Datastore can take a significant amount of time, especially for large datasets. This process might extend beyond a few hours, depending on data complexity and system load. It's advisable to wait for a considerable duration before retrying your query.
  2. Accuracy in Index Definition:

    • Carefully review your index.yaml file for any typos or errors. Ensure that the Kind name and property names in the index definition exactly match those in your application.
  3. Confirm Index Creation:

    • Use the gcloud datastore indexes list command to check the status of your new index. This will confirm whether the index has been created and is ready for use.
  4. Client-Side Data Handling:

    • While there isn't a direct method to clear the cache of the Datastore itself, ensure that any client-side caching mechanisms are not holding onto outdated data. Refreshing or clearing these caches might help your application recognize the latest index changes.
  5. Inspect Error Messages:

    • Pay close attention to the error messages from Datastore. They often contain specific details that can guide you in troubleshooting the issue.
  6. Manage Stale Indexes:

    • Use gcloud datastore indexes cleanup to remove unused indexes. However, proceed with caution, as this might inadvertently affect other parts of your application.

It turns out that I had my service env pointing to the wrong GCP project. Thank you for your help, though!