查询谷歌云数据存储与祖先没有返回任何东西

问题描述:

我在Google App Engine上使用灵活的环境google cloud datastore library查询谷歌云数据存储与祖先没有返回任何东西

我有我的父母使用pathway实体run实体:

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 

如何正确过滤父实体?

为了满足云数据存储需要建立索引的某些查询。详细信息在此处定义:https://cloud.google.com/datastore/docs/concepts/indexes

定义建议的索引应使查询有效。

+0

啊谢谢!看来我完成了错过了有关指数的位。 –