按国家/地区获取最大值,但我想要最大值 id 的其他信息。我尝试了很多方法,但我不知道如何获取。
{
"aggs" : {
"country_groups" : {
"terms" : { "field" : "country.keyword",
"size":30000
},
"aggs":{
"max_price":{
"max": { "field" : "video_count"}
}
}
} }
}
根据id
字段的类型(数字或字符串(,有两种方法可以做到这一点。
如果您查看下面的查询,如果您的id
是数字,您可以执行与video_count
相同的操作,即使用max
指标聚合(请参阅max_id_num
(。
但是,如果id
字段是字符串,则可以利用top_hits
聚合并按descending
顺序对其进行排序(请参阅max_id_str
(。
{
"aggs": {
"country_groups": {
"terms": {
"field": "country.keyword",
"size": 30000
},
"aggs": {
"max_price_and_id": {
"top_hits": {
"size": 1,
"sort": {
"video_count": "desc"
},
"_source": ["channel_id", "video_count"]
}
}
}
}
}
}