Hi,
This will do the trick:
aggs <- '{
"query": {
"match_all": {}
},
"aggs": {
"grouped_by_name": {
"terms": {
"field": "recordLocator",
"size": 0
},
"aggs": {
"top_tag_hits": {
"top_hits": {
"sort": [
{
"timestamp": {
"order": "desc"
}
}
],
"size": 1
}
}
}
}
}
}'
I get the feeling it is a bit slow though as it takes about 15 seconds and my index "only" has about 200 million records.