Ron*_*onZ 1 python indexing google-app-engine google-cloud-datastore
我正在尝试做简单的查询:
entity = DeviceLocation.query(ndb.StringProperty('deviceID') == data['deviceID']).order(-DeviceLocation.timestamp).get()
Run Code Online (Sandbox Code Playgroud)
每次它引发下一个错误:
NeedIndexError: no matching index found. recommended index is:
- kind: DeviceLocation
properties:
- name: deviceID
- name: timestamp
Run Code Online (Sandbox Code Playgroud)
问题是,即使我正在尝试创建索引(由此指导 - 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.
Run Code Online (Sandbox Code Playgroud)
据我了解,错误之间存在矛盾.这与group_by和相关projection.
目前,无法运行任何复杂的查询,这阻止了我取得任何进展.
小智 5
实际上,这不是一个"简单查询",因为您正在过滤deviceID和排序timestamp.
GAE指示您创建复合索引,这是您必须附加到index.yaml文件的内容:
- kind: DeviceLocation
properties:
- name: deviceID
- name: timestamp
Run Code Online (Sandbox Code Playgroud)
确保以此特定顺序包含这两个属性(deviceID和timestamp).
最后要改进的是你按属性过滤的方式:
DeviceLocation.deviceID == data['deviceID']
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
804 次 |
| 最近记录: |