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

问题描述 投票:17回答:5

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

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

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

 bars = bar_query.fetch(10)

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

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

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

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

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

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

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

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

任何帮助将不胜感激。

编辑:

我的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)
python-2.7 google-app-engine app-engine-ndb google-cloud-datastore
5个回答
14
投票

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

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


14
投票

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

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


6
投票

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

根据Google文档,故事是使用

gcloud app deploy 

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

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

gcloud datastore create-indexes index.yaml

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


4
投票

我修复了这个问题,方法是在“index.yaml”文件中将自动生成行上方错误所示的索引移动。

在您的情况下,yaml文件将如下所示:

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

# AUTOGENERATED

然后,您所要做的就是更新您的应用程序然后更新索引,您可以通过运行以下命令来更新索引。

appcfg.py [options] update_indexes <directory>

目录是相对于index.yaml文件的目录。 然后,您应该在https://appengine.google.com/datastore/indexes上的信息中心上看到该索引

此更新最初将处于“待处理”状态,但在索引显示“正在投放”后,您将能够进行查询。


0
投票

就我而言,我已手动上传索引文件,如下所示:

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

然后你应该确认更新:

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

然后,您可以转到数据存储控制台以检查是否已通过此链接创建索引: https//console.cloud.google.com/datastore/indexes

© www.soinside.com 2019 - 2024. All rights reserved.