我在Google App Engine上使用google cloud datastore library灵活的环境。
我有一个run
实体,我用它作为pathway
个实体的父级:
ds = datastore.Client('project-name')
parent = ds.query(kind='run', order=('-timestamp',)).fetch(1)
parent = list(parent)[0]
print(parent.key) # <Key('run', 1), project=project-name>
如果我获取一些pathway
个实体,它们似乎有正确的父
pathways = ds.query(kind='pathway', order=('-timestamp',)).fetch(limit=10)
for pathway in pathways:
print(pathway.key.parent) # <Key('run', 1), project=project-name>
但如果我尝试像这样过滤父母:
pathways = ds.query(kind='pathway', ancestor=parent.key, order=('-timestamp',)).fetch(limit=10)
然后我收到错误:
google.api.core.exceptions.PreconditionFailed
google.api.core.exceptions.PreconditionFailed: 412 no matching index found. recommended index is:
- kind: pathway
ancestor: yes
properties:
- name: timestamp
direction: desc
如何正确过滤父实体?
答案 0 :(得分:2)
为了满足某些查询,Cloud Datastore需要构建索引。详细信息在此处定义:https://cloud.google.com/datastore/docs/concepts/indexes
定义建议的索引应该使有问题的查询有效。