Google App Engine error: NeedIndexError: no matching index found

那年仲夏 提交于 2019-11-27 15:52:43

问题


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 following error:

NeedIndexError: no matching index found.
The suggested index for this query is:
- kind: Bar
  ancestor: yes
  properties:
  - name: rating
    direction: desc

The error is generated after this line of code:

 bars = bar_query.fetch(10)

Before the above line of code, it reads:

bar_query = Bar.query(ancestor=guestbook_key(guestbook_name)).order(-Bar.rating)

My index.yaml file contains the exact "suggested" index below # AUTOGENERATED:

- kind: Bar
  ancestor: yes
  properties:
  - name: rating
    direction: desc

Am I maybe missing something? I removed the index.yaml file and deployed the app again (via the command-line) and one less file was uploaded - so the index.yaml file is there.

Everything is working fine locally. I'm working on the latest Mac OSx. The command used for deployment was:

appcfg.py -A app-name --oauth2 update app

The datastore I implemented is loosely based on the guestbook tutorial app.

Any help would be greatly appreciated.

EDIT:

My ndb.Model is defined as follow:

class Bar(ndb.Model):
    content = ndb.StringProperty(indexed=False)
    lat = ndb.FloatProperty(indexed=False)
    lon = ndb.FloatProperty(indexed=False)
    rating = ndb.IntegerProperty(indexed=True)
    url = ndb.TextProperty(indexed=False)

回答1:


Check https://appengine.google.com/datastore/indexes to see if this index is present and status set to "serving". It's possible that the index is still being built.

The development environment emulates the production environment. It does not really have indexes in the Datastore sense.




回答2:


Probably a little late now, but running "gcloud app deploy index.yaml" helped since running deploy by itself ignored the index.yaml file.

As others have said, the dashboard at https://appengine.google.com/datastore/indexes will be showing "pending" for a while.




回答3:


I stumbled on the same issue and your comments helped me in the right direction. Here's what Google says how to handle this:

According to the Google documentation the story is that using

gcloud app deploy 

the index.yaml file is not uploaded (question is why not?). Anyway, one has to upload this index file manually.

To do so, the documentation gives the following command:

gcloud datastore create-indexes index.yaml

(supposing you execute this from the same directory of the index.yaml file) Once you have done this you can go to the Datastore console and you will see the index has been created. It will then start to be indexed (took some 5 minutes in my case) and once the index is being served you can start your application.




回答4:


I fixed this issue by moving the index that the error says is missing above the auto generate line in the "index.yaml" file.

In your case the yaml file will look like:

indexes:
- kind: Bar
 ancestor: yes
 properties:
 - name: rating
   direction: desc

# AUTOGENERATED

Then all you have to do is update your app then update the indexes, you update the indexes by running the following command.

appcfg.py [options] update_indexes <directory>

With the directory being the directory relative to your index.yaml file. You should then see that index on your dashboard at https://appengine.google.com/datastore/indexes

The update will initially be "pending" but after the index says "serving" you will be able to make your query.




回答5:


In my case, I have uploaded the index file manually like below:

gcloud datastore indexes create "C:\Path\of\your\project\index.yaml"

Then you should confirm the update:

Configurations to update:

descriptor:      [C:\Path\of\your\project\index.yaml]
type:            [datastore indexes]
target project:  [project_name]


Do you want to continue (Y/n)?  y

Then you can go to the Datastore console to check if the the index has been created via this link: https://console.cloud.google.com/datastore/indexes



来源:https://stackoverflow.com/questions/29807215/google-app-engine-error-needindexerror-no-matching-index-found

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