Google 与祖先的数据存储顺序

Google Datastore Order with ancestors

语言:Python。

我正在使用数据存储 python 库,一切正常。使用数据存储查询对查询结果进行排序时,我可以添加 query.order = ['name']; 对结果进行排序。但是当用祖先查询 table 时,比如:

ancestor = client.key('user', name, namespace = NAMESPACE)
query = client.query(kind='project', ancestor=ancestor, namespace = NAMESPACE)

然后我设置顺序:query.order = ['name'];,没用。我想排序 project,其祖先是 user。 报错信息是:“400 no matching index found. recommended index is:↵- kind: project↵ ancestor: yes↵ properties:↵ - name: name”,这是一个yaml示例。但是我这里没有使用 yaml。我认为一定有一种方法可以对结果进行排序,尽管有祖先。

所有数据存储查询都是基于索引的。来自 Indexes:

Every Google Cloud Datastore query computes its results using one or more indexes which contain entity keys in a sequence specified by the index's properties and, optionally, the entity's ancestors. The indexes are updated to reflect any changes the application makes to its entities, so that the correct results of all queries are available with no further computation needed.

您收到的错误来自数据存储区,表明数据存储区中缺少特定查询所需的索引。它与在您的应用程序代码中使用 yaml 进行祖先查询 and/or 无关。

yaml 引用只是来自将索引部署到数据存储的方式(这是您需要为查询工作做的事情),请参阅 Deploying or deleting indexes

因此您需要创建一个 index.yaml 文件,其中至少包含错误消息中指示的索引规范(以及其他查询可能需要的任何其他索引,如果有的话),将其部署到数据存储区,等待索引在 Indexes 页面上进入 Serving 状态(这可能需要一段时间),之后您的查询 应该 工作。