当前位置:  开发笔记 > 编程语言 > 正文

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

如何解决《GoogleAppEngine-NeedIndexError:找不到匹配的索引》经验,为你挑选了1个好方法。

我正在尝试做简单的查询:

entity = DeviceLocation.query(ndb.StringProperty('deviceID') == data['deviceID']).order(-DeviceLocation.timestamp).get()

每次它引发下一个错误:

NeedIndexError: no matching index found. recommended index is:
- kind: DeviceLocation
  properties:
  - name: deviceID
  - name: timestamp

问题是,即使我正在尝试创建索引(由此指导 - https://cloud.google.com/appengine/docs/python/datastore/indexes),deploy命令(gcloud app deloy index.yaml)返回此信息:

ERROR: (gcloud.app.deploy) Server responded with code [400]:
  Bad Request Unexpected HTTP status 400.
  Creating a composite index failed for entity_type: "DeviceLocation"
ancestor: false
Property {
  name: "timestamp"
  direction: 2
}
: This index:
IndexDef{form=SCANNER_BUILTIN_SINGLE_PROPERTY, kind=DeviceLocation, isAncestor=false, propertyDefs=[PropertyDef{path=timestamp, direction=DESCENDING, mode=null}]}
is not necessary, since single-property indices are built in. Please remove it from your index file and upgrade to the latest version of the SDK, if you haven't already.

据我了解,错误之间存在矛盾.这与group_by和相关projection.

目前,无法运行任何复杂的查询,这阻止了我取得任何进展.



1> 小智..:

实际上,这不是一个"简单查询",因为您正在过滤deviceID和排序timestamp.

GAE指示您创建复合索引,这是您必须附加到index.yaml文件的内容:

- kind: DeviceLocation
  properties:
  - name: deviceID
  - name: timestamp

确保以此特定顺序包含这两个属性(deviceIDtimestamp).

最后要改进的是你按属性过滤的方式:

DeviceLocation.deviceID == data['deviceID']

推荐阅读
夏晶阳--艺术
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有