Including only nested documents that caused the 'hit' of the parent doc

I have an index that looks something like this:

{
  field:'value',
  // ... more fields ...
  prices: [{"date":"2016-01-01", "nights":1, "price":300},...]
}

The prices array can contain around 10,000 entries per document.

I have a search query that will fetch all documents were the date and nights and price values all meet some requirements like "where date is X, nights is Y and price is between A and B"

When I fetch the results, I have to exclude the prices array from the source fields as it's way too big to be performant when retrieving 50 documents.

What I would like to do is retrieve the price entries that caused the doc to match in the first place.

Have you tried using inner_hits? https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html

I am on that page right now :slight_smile: thanks.