# Inner\_hits queries break from 1.7 to 2.3 in Elasticsearch

**URL:** <https://discuss.elastic.co/t/inner-hits-queries-break-from-1-7-to-2-3-in-elasticsearch/54242>\
**Category:** Elasticsearch\
**Created:** [June 29, 2016, 6:33am UTC](https://discuss.elastic.co/t/inner-hits-queries-break-from-1-7-to-2-3-in-elasticsearch/54242 "2016-06-29T06:33:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![siddharthgoel88](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/siddharthgoel88/32/10616_2.png) [@siddharthgoel88](https://discuss.elastic.co/u/siddharthgoel88)\
**Post date:** [June 29, 2016, 6:33am UTC](https://discuss.elastic.co/t/inner-hits-queries-break-from-1-7-to-2-3-in-elasticsearch/54242/1 "2016-06-29T06:33:07Z")

</div>

I have my question on stackoverflow at [http://stackoverflow.com/questions/38091130/inner-hit-definition-with-the-name-typename-already-exists-use-a-different-in](http://stackoverflow.com/questions/38091130/inner-hit-definition-with-the-name-typename-already-exists-use-a-different-in) but for completeness I will put the details of my query here also.

I have had a search query with the following payload 🙂

```
 "query": {
    "filtered": {
        "filter": {
            "and": [
                {
                    "range": {
                        "@timestamp": {
                             "gte": "2015-01-01||/d",
                             "lte": "2016-01-01||/d"
                        }
                    }
                },
                {
                    "or": [
                        {
                            "has_child": {
                                "type": "TypeName",
                                "filter": {
                                    "term": {
                                        "eventType.raw": "some-event"
                                    }
                                },
                                "inner_hits": {
                                    "_source": "@timestamp"
                                }
                            }
                        },
                        {
                            "not": {
                                "has_child": {
                                    "type": "TypeName",
                                    "filter": {
                                        "term": {
                                            "eventType.raw": "some-event"
                                        }
                                    },
                                    "inner_hits": {
                                        "_source": "@timestamp"
                                    }
                                }
                            }
                        }
                    ]
                }
            ]
        }
    }
}

```

and this was working fine with elasticsearch 1.7 but with the latest stable version 2.3.3 of elasticsearch it does not quite work and fails with the following response 🙂

```
"reason": {
   "type": "illegal_argument_exception",
   "reason": "inner_hit definition with the name [TypeName] already exists. Use a different inner_hit name"
}

```

Any idea what could have gone wrong here?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 29, 2016, 8:26am UTC](https://discuss.elastic.co/t/inner-hits-queries-break-from-1-7-to-2-3-in-elasticsearch/54242/2 "2016-06-29T08:26:52Z")

</div>

I'm not expert on inner hits and parent child but it looks like a bug, no?

Can you format your question please so it's more readable?

---

<div class="post-metadata">

**Author:** ![siddharthgoel88](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/siddharthgoel88/32/10616_2.png) [@siddharthgoel88](https://discuss.elastic.co/u/siddharthgoel88)\
**Post date:** [June 29, 2016, 8:43am UTC](https://discuss.elastic.co/t/inner-hits-queries-break-from-1-7-to-2-3-in-elasticsearch/54242/3 "2016-06-29T08:43:55Z")

</div>

Thanks for your reply @dadoonet . I also felt it to be a bug but I am fairly new (~1 week old) to ES was not 100% sure if this is really one. What would you suggest in this case then?

For now I created an issue on github for the same, [https://github.com/elastic/elasticsearch/issues/19142](https://github.com/elastic/elasticsearch/issues/19142) .

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [June 29, 2016, 9:39am UTC](https://discuss.elastic.co/t/inner-hits-queries-break-from-1-7-to-2-3-in-elasticsearch/54242/4 "2016-06-29T09:39:29Z")

</div>

This isn't a bug, but maybe the error description can be a bit clearer?  
The problem is that you have two inner hits definitions in your request that use the same name. The default name is based on the `type` inside of the `has_child` query. You can provide a custom name by specifying `name` field inside the `inner_hits` definition. The inner\_hit name is important here, because that is used in the response to identify to what inner\_hit definition the inner hits belong to.

The following request should work:

```auto
{
"query": {
    "filtered": {
        "filter": {
            "and": [
                {
                    "range": {
                        "@timestamp": {
                             "gte": "2015-01-01||/d",
                             "lte": "2016-01-01||/d"
                        }
                    }
                },
                {
                    "or": [
                        {
                            "has_child": {
                                "type": "TypeName",
                                "filter": {
                                    "term": {
                                        "eventType.raw": "some-event"
                                    }
                                },
                                "inner_hits": {
                                    "_source": "@timestamp",
                                    "name" : "inner_hit1"
                                }
                            }
                        },
                        {
                            "not": {
                                "has_child": {
                                    "type": "TypeName",
                                    "filter": {
                                        "term": {
                                            "eventType.raw": "some-event"
                                        }
                                    },
                                    "inner_hits": {
                                        "_source": "@timestamp",
                                        "name" : "inner_hit2"
                                    }
                                }
                            }
                        }
                    ]
                }
            ]
        }
    }
}
}

```

---

<div class="post-metadata">

**Author:** ![siddharthgoel88](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/siddharthgoel88/32/10616_2.png) [@siddharthgoel88](https://discuss.elastic.co/u/siddharthgoel88)\
**Post date:** [June 29, 2016, 10:40am UTC](https://discuss.elastic.co/t/inner-hits-queries-break-from-1-7-to-2-3-in-elasticsearch/54242/5 "2016-06-29T10:40:58Z")

</div>

@mvg Thanks for your reply. Your proposed changes makes the query work 🙂

---

<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:** [July 5, 2017, 10:39pm UTC](https://discuss.elastic.co/t/inner-hits-queries-break-from-1-7-to-2-3-in-elasticsearch/54242/6 "2017-07-05T22:39:37Z")

</div>


