I\'m having trouble with Google\'s App engine indexes. When running my app via the GoogleAppEngineLauncher, the app is working fine. When deploying the app, I get the follow
This NeedIndexError can be triggered by different causes, as I arrived here while having a slightly different problem, so I'll try to explain all I was doing wrong in order to show things that can be done:
I thought I have to had only one index per Kind of entity. That's not true, as long as I found you need to have as many indexes as different queries you will need to make.
While on development web server indexes are autogenerated and placed below the #AUTOGENERATED line in index.yaml file.
After modifying indexes I use first gcloud datastore indexes create index.yaml and I wait until indexes are Serving in https://console.cloud.google.com/datastore/indexes?project=your-project.
I clean unused indexes by executing gcloud datastore indexes cleanup index.yaml be aware that you do not delete indexes that are being used on production. Reference here
Be aware that if you don't specify direction on your index properties, it will be ASC by default. So if you are trying to make a - sort query it will again rise the error.
Things I think but I have not 100% evidence longer than my particular problem, but I think can help as a kind of brainstorming:
Indexes are important while querying data, not when uploading.
Creating manually the #AUTOGENERATED line not seem to be necessary if you are generating indexes manually. Reference here
As the development server updates indexes below #AUTOGENERATED line while making queries, you can "accidentally" solve your problem by adding this lane. While the real problem is a lack of manually index update using gcloud datastore indexes create index.yaml command. Reference here and here