# Query with multiple has\_children clauses

**URL:** https://discuss.elastic.co/t/query-with-multiple-has-children-clauses/159987
**Category:** Elasticsearch
**Created:** [December 8, 2018, 12:03am UTC](https://discuss.elastic.co/t/query-with-multiple-has-children-clauses/159987 "2018-12-08T00:03:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Andrew\_Hackley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_hackley/32/38583_2.png) [@Andrew\_Hackley](https://discuss.elastic.co/u/Andrew_Hackley)
#### Post date: [December 8, 2018, 12:03am UTC](https://discuss.elastic.co/t/query-with-multiple-has-children-clauses/159987/1 "2018-12-08T00:03:30Z")

</div>

I'd like to know if it's possible to have multiple has\_children clauses in one query. I've not been able to get it to work. Here's an example of what I'm trying:

```
GET test-index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "field1": "value1"
          }
        },
        {
          "has_child": {
            "type": "joinDocValue",
            "query": {
              "match": {
                "field2": "value2"
              }
            }
          }
        },
        {
          "has_child": {
            "type": "joinDocValue2",
            "query": {
              "match": {
                "field3": "value3"
              }
            }
          }
        }
      ]
    }
  }
}

```

I saw this earlier topic: [Has\_child query with multiple type?](https://discuss.elastic.co/t/has-child-query-with-multiple-type/125165) where @jimczi mentioned you can have only one query per child type. It's not clear to me what exactly that means though.

The [has\_child documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html) indicates that multiple has\_children clauses in one query should be possible (although slow compared to not using parent child mappings). Specifically the documentation mentions:

> Each has\_child query that gets added to a search request can increase query time significantly

So obviously putting multiple has\_child conditions together will significantly slow down the query... but it definitely sounds possible. I'd very much like to benchmark a few different mappings use cases which essentially require multi-has\_child conditions in one query. Can anyone help form the multi-has\_child query that the documentation indicates is possible?

Thank you!

---

<div class="post-metadata">

### Author: ![Andrew\_Hackley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_hackley/32/38583_2.png) [@Andrew\_Hackley](https://discuss.elastic.co/u/Andrew_Hackley)
#### Post date: [December 10, 2018, 4:26pm UTC](https://discuss.elastic.co/t/query-with-multiple-has-children-clauses/159987/2 "2018-12-10T16:26:08Z")

</div>

On re-inspection this query does work as written above.... It was the document seeding that I was messing up. 😕

Well, if anyone needs assistance forming a multi-condition has\_child query, hopefully this post's query example will still be of help to you!

---

<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: [January 7, 2019, 4:26pm UTC](https://discuss.elastic.co/t/query-with-multiple-has-children-clauses/159987/3 "2019-01-07T16:26:16Z")

</div>

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