您可以使用
top_hits将
country字段分组的聚合,每组返回1个文档,并按收集日期降序排列文档:
POST /test/_search?search_type=count{ "aggs": { "group": { "terms": { "field": "country" }, "aggs": { "group_docs": { "top_hits": { "size": 1, "sort": [ { "collected": { "order": "desc" } } ] } } } } }}


