Google App Engine错误:NeedIndexError:找不到匹配的索引

ISJ*_*ISJ 17 google-app-engine python-2.7 app-engine-ndb google-cloud-datastore

我在使用谷歌的App引擎索引时遇到了麻烦.通过GoogleAppEngineLauncher运行我的应用程序时,该应用程序运行正常.部署应用程序时,我收到以下错误:

NeedIndexError: no matching index found.
The suggested index for this query is:
- kind: Bar
  ancestor: yes
  properties:
  - name: rating
    direction: desc
Run Code Online (Sandbox Code Playgroud)

在这行代码之后生成错误:

 bars = bar_query.fetch(10)
Run Code Online (Sandbox Code Playgroud)

在上面的代码行之前,它显示为:

bar_query = Bar.query(ancestor=guestbook_key(guestbook_name)).order(-Bar.rating)
Run Code Online (Sandbox Code Playgroud)

我的index.yaml文件包含#AUTOGENERATED下面的确切"建议"索引:

- kind: Bar
  ancestor: yes
  properties:
  - name: rating
    direction: desc
Run Code Online (Sandbox Code Playgroud)

我可能错过了什么吗?我删除了index.yaml文件并再次部署了应用程序(通过命令行),并且上传了一个较少的文件 - 所以index.yaml文件就在那里.

一切都在当地很好.我正在研究最新的Mac OSx.用于部署的命令是:

appcfg.py -A app-name --oauth2 update app
Run Code Online (Sandbox Code Playgroud)

我实现的数据存储区基于留言簿教程应用程序.

任何帮助将不胜感激.

编辑:

我的ndb.Model定义如下:

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)
Run Code Online (Sandbox Code Playgroud)

And*_*gin 14

检查https://appengine.google.com/datastore/indexes以查看此索引是否存在且状态是否设置为"正在投放".索引可能仍在构建中.

开发环境模拟生产环境.它在数据存储区意义上并没有真正的索引.


小智 14

可能现在有点晚了,但运行"gcloud app deploy index.yaml"有帮助,因为运行部署本身忽略了index.yaml文件.

正如其他人所说,https: //appengine.google.com/datastore/indexes上的信息中心将暂时显示"待定"状态.

  • 如果使用appcfg.py或appcfg.sh命令将应用程序部署到App Engine,则会自动部署索引配置文件.如果使用gcloud app deploy命令部署应用程序,则不会自动部署索引配置文件.您必须将index.yaml专门列为gcloud app deploy的参数,或者运行gcloud datastore create-indexes以部署索引配置文件. (5认同)

kxt*_*nic 6

我偶然发现了同样的问题,你的意见帮助我朝着正确的方向前进.以下是谷歌如何处理这个:

根据Google文档,故事是使用

gcloud app deploy 
Run Code Online (Sandbox Code Playgroud)

index.yaml文件没有上传(问题是为什么不上传?).无论如何,必须手动上传此索引文件.

为此,文档提供以下命令:

gcloud datastore create-indexes index.yaml
Run Code Online (Sandbox Code Playgroud)

(假设您从index.yaml文件的同一目录执行此操作)完成此操作后,您可以转到数据存储控制台,您将看到已创建索引.然后它将开始编入索引(在我的情况下花了大约5分钟),一旦提供索引,您就可以开始申请了.