I have observed a strange behavior for nested queries which I do not understand. Here is an example query:
{
    "query" : {
        "nested" : {
            "path" : "first.nested.path",
            "query" : {
                "bool" : {
                    "filter" : [{
                            "term" : {
                                "first.nested.path.general.something" : "ABC"
                            }
                        }, {
                            "nested" : {
                                "path" : "first.nested.path.second.path",
                                "query" : {
                                    "bool" : {
                                        "filter" : [{
                                                "term" : {
                                                    "first.nested.path.second.path.value" : "Hello"
                                                }
                                            }, {
                                                "term" : {
                                                    "first.nested.path.second.path.value2" : "World"
                                                }
                                            }
                                        ]
                                    }
                                }
                            }
                        }
                    ]
                }
            }
        }
    },
    "inner_hits" : {
        "kids" : {
            "path" : {
                "first.nested.path" : {
                    "query" : {
                        "term" : {
                            "first.nested.path.general.something" : "ABC"
                        }
                    },
                    "_source" : false,
                    "fielddata_fields" : ["first.nested.path.general.something"],
                    "inner_hits" : {
                        "kids" : {
                            "path" : {
                                "first.nested.path.second.path" : {
                                    "query" : {
                                        "bool" : {
                                            "filter" : [{
                                                    "term" : {
                                                        "first.nested.path.second.path.value" : "Hello"
                                                    }
                                                }, {
                                                    "term" : {
                                                        "first.nested.path.second.path.value2" : "World"
                                                    }
                                                }
                                            ]
                                        }
                                    },
                                    "_source" : false,
                                    "fielddata_fields" : ["first.nested.path.second.path.value", "first.nested.path.second.path.value2"]
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
This query returns empty inner_hits for some results. But how is this possible?
I have checked the original data and found that the filters apply (so it is correct that the result is returned), but for some reason the inner_hits are not shown.
What are possible reasons for this?
I am also not quite sure about how to include query->bool->filter->term in the inner_hits definition. Should it be:
 "query" : {
                            "term" : {
(like above)
OR:
"query" : {
                        "filtered": {
                            "filter": {
                                "term" : {
?
In general, this part of the query DSL is pretty awkward (see also: