Reputation: 321
How can I select what fields get returned in an aggregation bucket?
I have a bunch of fields in my data like
Document:{
"contenthash": "0a12ac12ac12ac12ac12ac12"
"time": "01:01:01"
"Content": "hello"
}
When I aggregate on the content hash, I get a bucket containing just the content hash and not the other fields. What I want to be able to do is return all fields associated with that content hash. So I have:
"buckets": {
"key" :{ "0a12ac12ac12ac12ac12ac12":
"time" : "01:01:01"
"Content" : "hello"}
I know I can do a sub aggregation to get to the data under the content hash, but is there an easier way?
Upvotes: 1
Views: 1245
Reputation: 1769
I believe what you are looking for is the top hits aggregation.
If you designed your aggregation to be something like this:
{
"aggs": {
"byHash" : {
"terms": {
"field" : "contenthash"
},
"aggs": {
"top": {
"top_hits": {
"size": 10
}
}
}
}
}
}
You would then see, for each unique contenthash, the most relevant source documents that were aggregated in that contenthash bucket.
Upvotes: 1