gpt4 book ai didi

java - 使用 Jest 在 Elasticsearch 中删除没有父文档的子文档

转载 作者:行者123 更新时间:2023-12-02 22:14:17 25 4
gpt4 key购买 nike

正如标题所说,我正在尝试使用 Jest 删除所有无父子文档。如果我做对了,我需要使用 DeleteByQuery,我建议的解决方案是:

val allParentlessChildren = QueryBuilders
.boolQuery()
.mustNot(JoinQueryBuilders.hasParentQuery(
"my_parent",
QueryBuilders.matchAllQuery(),
false)
)
val delete = new DeleteByQuery.Builder(allParentlessChildren.toString)
.addIndex("my_index")
.addType("my_child")
.build()

但是,我得到了 routing_missing_exceptionInvestigating online ,似乎我需要为路由设置父类型,但是,除了在 hasParentQuery idk 中指定它之外,我还需要在哪里添加它?

虽然我找到了some examples如何使用 REST API 做到这一点,我找不到使用 Jest 的 API,所以希望有人能帮忙。

我正在使用 Elasticsearch 5.5。

最佳答案

只需要添加路由,然而,在 Jest 中它似乎稍微隐藏在 setParameter 方法中:

val delete = new DeleteByQuery.Builder(allParentlessChildren.toString)
.addIndex("my_index")
.addType("my_child")
.setParameter(Parameters.ROUTING, "my_parent") // <-- added line
.build()

关于java - 使用 Jest 在 Elasticsearch 中删除没有父文档的子文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63575169/

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