I was trying to build from here:
GET /my_index/_search
query: {
match: {
'foo': 'bar'
}
},
aggs: {
'agg1': {
terms: {
field: 'some_field.keyword'
}
}
}
But I didn't get anywhere. Because this way the results I get are from all documents that match 'foo' = 'bar', an array of buckets for each value of 'some_field'. And the buckets only give me the possible values of 'some_field' and the document count. For each bucket I want to get the whole document with the most recent timestamp, i.e., order by timestamp desc, and limiting to 1 document per possible value of 'some_field'.
Is aggregations the best way to get this? It seems I only get the document count with the buckets. Is there any other approach that might be better to do this?