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

huangapple go评论72阅读模式
英文:

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(&quot;my_index&quot;)
    .addType(&quot;my_child&quot;)
    .setParameter(Parameters.ROUTING, &quot;my_parent&quot;) // &lt;-- added line
    .build()

huangapple
  • 本文由 发表于 2020年8月25日 16:44:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63575169.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定