# Using Has Parent Query how can I return specific Child

**URL:** <https://discuss.elastic.co/t/using-has-parent-query-how-can-i-return-specific-child/144454>\
**Category:** Elasticsearch\
**Created:** [August 15, 2018, 5:55am UTC](https://discuss.elastic.co/t/using-has-parent-query-how-can-i-return-specific-child/144454 "2018-08-15T05:55:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![code\_blue](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@code\_blue](https://discuss.elastic.co/u/code_blue)\
**Post date:** [August 15, 2018, 5:55am UTC](https://discuss.elastic.co/t/using-has-parent-query-how-can-i-return-specific-child/144454/1 "2018-08-15T05:55:59Z")

</div>

I have a scenario where a Parent "Car" has children "Toyota" & "Honda". If I run the below Has Parent Query it will return all children's of Car but I am looking is there a way to return only a specific children of Car.

```
GET /_search
{
    "query": {
        "has_parent" : {
            "parent_type" : "Car",
            "query" : {
                "term" : {
                    "origin" : "USA"
                }
            }
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![jaddison](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jaddison](https://discuss.elastic.co/u/jaddison)\
**Post date:** [September 10, 2018, 4:12pm UTC](https://discuss.elastic.co/t/using-has-parent-query-how-can-i-return-specific-child/144454/2 "2018-09-10T16:12:38Z")

</div>

It helps if you provide sample documents, the index settings/document mapping, and in the case of parent/child relationships, which ES version you're using (a semi-significant change occurred between versions 5.x and 6)

Based on the information provided, to return specific children you'd just need to add addition query clauses:

```auto
GET /_search
{
    "query": {
        "bool": {
            "must": [
                {
                    "has_parent" : {
                        "parent_type" : "Car",
                        "query" : {
                            "term" : {
                                "origin" : "USA"
                            }
                        }
                    }
                },
                {
                    "term": {"color": {"value": "red"}}
                }
            ]
        }
    }
}

```

But perhaps I'm misunderstanding your question.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 8, 2018, 4:12pm UTC](https://discuss.elastic.co/t/using-has-parent-query-how-can-i-return-specific-child/144454/3 "2018-10-08T16:12:59Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
