# Elasticsearch inner-hits on child type not in the query

**URL:** <https://discuss.elastic.co/t/elasticsearch-inner-hits-on-child-type-not-in-the-query/103973>\
**Category:** Elasticsearch\
**Created:** [October 14, 2017, 5:18am UTC](https://discuss.elastic.co/t/elasticsearch-inner-hits-on-child-type-not-in-the-query/103973 "2017-10-14T05:18:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![smndiaye](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@smndiaye](https://discuss.elastic.co/u/smndiaye)\
**Post date:** [October 14, 2017, 5:18am UTC](https://discuss.elastic.co/t/elasticsearch-inner-hits-on-child-type-not-in-the-query/103973/1 "2017-10-14T05:18:35Z")

</div>

Struggling with inner-hits on elasticsearch. Would appreciate any help.

I have two child types: childA and childB.  
I am querying parents of childA like this

```
"query":{
    "bool": {
        "should": {
            "has_child": {
                "type": "ChildA",
                "query": {
                    "match": {
                        "name": {
                            "query": "a" 
                        }
                    }
                }
            }
        }
    }
} 

```

My problem is how to include in the results all child docs of type childB as well without affecting results from the above query.

I was thinking to use inner-hits on a has\_child query(type childB) for that but my query doesn't depend on childB type.

Anyone has an idea?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![smndiaye](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@smndiaye](https://discuss.elastic.co/u/smndiaye)\
**Post date:** [October 14, 2017, 10:01am UTC](https://discuss.elastic.co/t/elasticsearch-inner-hits-on-child-type-not-in-the-query/103973/2 "2017-10-14T10:01:14Z")

</div>

I found a way to include childB type docs.

I combine the following query with above query (has\_child on childA type) in a filter query to get childB docs also. I am not really sure if its a good way though(thinking about performance)

```auto
{
      "query":{
        "bool":{
          "should":[
            {
              "bool":{
                "must_not":[
                  {
                    "has_child":{
                      "type":"ChildB",
                      "query":{
                        "match_all":{}
                      },
                      "inner_hits":{}
                    }
                  }
                ]
              }
            },
            {
              "has_child":{
                "type":"ChildB",
                "query":{
                  "match_all":{}
                },
                "inner_hits":{}
              }
            }
          ]
        }
      }
    }

```

---

<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:** [November 11, 2017, 10:01am UTC](https://discuss.elastic.co/t/elasticsearch-inner-hits-on-child-type-not-in-the-query/103973/3 "2017-11-11T10:01:14Z")

</div>

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