简体   繁体   中英

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. 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.

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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