How to search parent document without children?

Hi Lyudmila_Fokina,

You just save my life. :+1: :+1: :+1: The query you shared is working.
Now the result returns the parent document when there no children as I want to delete all the parent resume that not longer contain children.

(is there a better way to delete parent doc without retrieve, loop, and delete ?)
like one API call that helps clean up will be awesome if exist)

I changed the 2nd query to make it happen as the"relation_type" field is not working.
The "relation_type" you shared suppose to change to "my_join_field"?

"match": {
   "my_join_field": "###parent###"
}

Full working query

{
    "query": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "must_not": {
                            "has_child": {
                                "type": "###child###",
                                "query": {
                                    "match_all": {}
                                }
                            }
                        }
                    }
                },
                {
                    "match": {
                        "my_join_field": "###parent###"
                    }
                }
            ]
        }
    },
    "size": 10
}