Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.

Has Parent Query

More info about has parent query is in the official elasticsearch docs

The has parent query accepts a query and a parent type. The query is executed in the parent document space, which is specified by the parent type. This filter returns child documents which associated parents have matched.

Simple example

{
    "has_parent" : {
        "parent_type" : "blog",
        "query" : {
            "term" : {
                "tag" : "something"
            }
        }
    }
}

In DSL:

$termQuery = new TermQuery('tag', 'something');

$hasParentQuery = new HasParentQuery('blog', $termQuery);

$search = new Search();
$search->addQuery($hasParentQuery);

$queryArray = $search->toArray();