Elasticsearch OR query with nested objects returns inner_hits not matching the criteria

Kind of unfortunate that no one has responded here. I understand that with nested docs, you are really querying that main index, and can't directly query the nested parts separately. But I'd really like to know how we can achieve what is being asked here.

Namely, I want the set of nested documents that match some criteria. But when that criteria includes an OR as in this example, you can see that things get muddled - you get all the inner_hits for the document that match.

When I've asked elsewhere some folks seem to think I should flatten and not use nested or use a separate index for the "children" and the "parent". But in my case, I can't flatten because the nested doc really has multiple fields and I want to query where some nested doc has multiple properties being true. And I also do want to join with the parent - so separate indexes make the join impossible.

I also did look at parent/child - but the advise here is always to avoid because of maintenance and performance concerns. Also with ES 6, it would seem that parent/child is advised against even more so - as we no longer have types (and my parent and child are certainly different types).

So is there a way to precisely get the set of nested docs that I'm looking for, even in the case of an OR condition as shown in the nice example by the original poster?

1 Like