4

In Elasticsearch, is there any way to exclude the nested objects that don't match a particular query/filter from the resulting _source?

For example, let's say that a document has four objects in a nested field. Querying on the required filters results in only matching objects 1 and 3. When we get the results via _source, we will pull back the entire document along with objects 1,2,3,4.

Is it possible to exclude objects 2 and 4 from the results? Or is that something that we have to re-iterate and exclude using application-side logic?

2 Answers 2

4

You can achieve this with use of inner_hits which will return you only matching nested objects. you can exclude this nested field in source.

Suggested by Val at: ElasticSearch - Get only matching nested objects with All Top level fields in search response

Sign up to request clarification or add additional context in comments.

Comments

3

At the moment there is no way to include only the matched nested objects in the result.

There is a inner_hits feature coming out in elasticsearch 1.5.0 which should help with this.

1 Comment

Great to hear. This is something I wanted to be able to do too, and couldn't find any way to do it currently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.