shulard
shulard

Reputation: 603

How to retrieve documents with a broken parent->child relationship?

I'm currently working on scripts to manage an Elasticsearch cluster and ensure data integrity.

The index use the parent > child relationship between documents. Is there a way to retrieve the list of child with invalid parents (parent id referencing deleted document) ?

Upvotes: 1

Views: 279

Answers (1)

keety
keety

Reputation: 17461

You can probably use a query on the following lines to get the list of orphan child documents

POST /<index_name>/<child_type>/_search
{
   "filter": {
      "not": {
         "has_parent": {
            "parent_type": "<parent_type>",
             "query": {
                "match_all": {}
             }
         }
      }
   }
}

Upvotes: 3

Related Questions