简体   繁体   English

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

[英]Delete child documents without parent in Elasticsearch using Jest

As the title says, I'm trying to delete all the parentless child documents using Jest.正如标题所说,我正在尝试使用 Jest 删除所有无父子文档。 If I got things correctly, I need to use DeleteByQuery, and my proposed solution is this:如果我做对了,我需要使用 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()

However, I get routing_missing_exception .但是,我得到了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? 在线调查,似乎我需要为路由设置父类型,但是,除了在hasParentQuery idk 中指定它hasParentQuery ,我还需要在哪里添加它?

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.尽管我找到了一些如何使用 REST API 进行操作的示例,但我找不到使用 Jest 的示例,因此希望有人可以提供帮助。

I'm using Elasticsearch 5.5.我正在使用 Elasticsearch 5.5。

Just needed to add routing, however, in Jest it seems it's slightly hidden in the setParameter method:只需要添加路由,然而,在 Jest 中它似乎隐藏在setParameter方法中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM