我正在尝试做简单的查询:
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
.
目前,无法运行任何复杂的查询,这阻止了我取得任何进展.
实际上,这不是一个"简单查询",因为您正在过滤deviceID
和排序timestamp
.
GAE指示您创建复合索引,这是您必须附加到index.yaml
文件的内容:
- kind: DeviceLocation properties: - name: deviceID - name: timestamp
确保以此特定顺序包含这两个属性(deviceID
和timestamp
).
最后要改进的是你按属性过滤的方式:
DeviceLocation.deviceID == data['deviceID']