gpt4 book ai didi

google-app-engine - 祖先查询导致 API 错误 4 (datastore_v3 : NEED_INDEX): no matching index found error

转载 作者:数据小太阳 更新时间:2023-10-29 03:07:33 26 4
gpt4 key购买 nike

我在处理祖先查询时遇到了很大的困难。

这是有效的代码:

...
uk := datastore.NewKey(c, config.DatastoreDuelIdKind, did, 0, nil)
_, err := datastore.NewQuery(config.DatastoreQuestionInDuelKind).Ancestor(uk).GetAll(c, &roundsPlayedInDuel)
...

上面的代码产生了正确的结果。现在,如果我在 config.DatastoreQuestionInDuelKind 的属性上添加 Order 过滤器,查询将失败并出现 NEED_INDEX 错误。

但是这个失败了:

_, err := datastore.NewQuery(config.DatastoreQuestionInDuelKind).Order("RoundNumber").Ancestor(uk).GetAll(c, &roundsPlayedInDuel)

唯一的区别是添加了 Order 过滤器。

现在,我在 index.yaml 中定义了一个索引,如下所示:

索引:

- kind: gcx_Round_Id_Duel_Id
properties:
- name: DId
- name: RoundNumber

从 App Engine 仪表板我可以看到,它正在服务。仍然收到索引错误。有什么想法吗?

最佳答案

您的索引缺少 'ancestor' 属性,并且您的查询似乎没有使用 'DId',因此无需包含它:

- kind: gcx_Round_Id_Duel_Id
ancestor: yes
properties:
- name: RoundNumber

您必须显式定义此索引,因为您将祖先查询与排序组合在一起 - 自动索引将允许您单独执行其中任何一项。 (因此,如果您正在获取所有实体,那么放弃查询排序然后使用代码对返回的实体进行排序可能会更有效。)

关于google-app-engine - 祖先查询导致 API 错误 4 (datastore_v3 : NEED_INDEX): no matching index found error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23448087/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com