英文:
Delete child documents without parent in Elasticsearch using Jest
问题
按照标题所述,我正在尝试使用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_exception
错误。在线调查,似乎我需要为路由设置父类型,除了在hasParentQuery
中指定外,我不知道还需要在哪里添加?
尽管我找到了一些示例如何使用REST API完成,但我无法找到使用Jest的示例,希望有人可以帮忙。
我使用的是Elasticsearch 5.5。
英文:
As the title says, I'm trying to delete all the parentless child documents using Jest. If I got things correctly, I need to use DeleteByQuery, and my proposed solution is this:
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()
However, I get routing_missing_exception
. Investigating online, it seems I need to set parent type for routing, however, apart from specifying it in hasParentQuery
idk where else I need to add it?
Although I found some examples how to do it with REST API, I wasn't able to find ones that use Jest, so hopefully someone can help out.
I'm using Elasticsearch 5.5.
答案1
得分: 0
只需要添加路由,然而在 Jest 中,它似乎在 setParameter
方法中稍微隐藏起来:
val delete = new DeleteByQuery.Builder(allParentlessChildren.toString)
.addIndex("my_index")
.addType("my_child")
.setParameter(Parameters.ROUTING, "my_parent") // <-- 添加的行
.build()
英文:
Just needed to add routing, however, in Jest it seems it's slightly hidden in the setParameter
method:
val delete = new DeleteByQuery.Builder(allParentlessChildren.toString)
.addIndex("my_index")
.addType("my_child")
.setParameter(Parameters.ROUTING, "my_parent") // <-- added line
.build()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论