Example mapping
{
properties: {
key: { type: 'keyword' },
title: { type: 'text' },
releases: {
type: 'nested',
properties: {
key: { type: 'keyword' },
title: { type: 'text' }
}
}
}
}
Where the top level "title" is the Album title, and release.title is the Track title.
We are interested in querying the "Releases" array and not so interested in the top level document
i.e. if the Album title is "Texas", it has 3 releases named "Alpha", "Bravo" and "Charlie", we want to text search by the word "Bravo" and get back a result that allows us to single out the release Bravo, and ignore the other two
We figure we need to use this: https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-aggregations-metrics-top-hits-aggregation.html#_top_hits_support_in_a_nested_or_reverse_nested_aggregator
A top hits aggregator inside a nested aggregator, to get back either just the releases bit, or the full document, but with a _nested property to indicate the matching potion of the document that matched
Is that the right query? What would it return? Is there a better way? What would it look like?