Inner_hits queries break from 1.7 to 2.3 in Elasticsearch

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 but for completeness I will put the details of my query here also.

I have had a search query with the following payload :slight_smile:

 "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 :slight_smile:

"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?

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?

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 .

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:

{
"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"
                                    }
                                }
                            }
                        }
                    ]
                }
            ]
        }
    }
}
}
2 Likes

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