Es版本2.4.6,求教一个问题,对一个字段进行分组查询,在查询分组里面比如说成绩最高的一条文档,aggs语句该怎么写
Elasticsearch | 作者 yunzaiqintian | 发布于2017年10月31日 | 阅读数:4030
比如有5个组那么返回每个组时间最靠后的一条信息(共5条)下面写的是 对birth取最近的一条记录,怎么根据ID分组查出来
{
"size": 0,
"aggs": {
"top_age": {
"top_hits": {
"sort": [
{
"birth": {
"order": "desc"
}
}
],
"_source": {
"include": [
"id",
"name",
"birth"
]
},
"size": 1
}
}
}
}
{
"size": 0,
"aggs": {
"top_age": {
"top_hits": {
"sort": [
{
"birth": {
"order": "desc"
}
}
],
"_source": {
"include": [
"id",
"name",
"birth"
]
},
"size": 1
}
}
}
}
1 个回复
yunzaiqintian
赞同来自:
"size": 0,
"aggs": {
"group_by_id": {
"terms": {
"field": "id"
}, "aggs": {
"top_age": {
"top_hits": {
"sort": [
{
"birth": {
"order": "desc"
}
}
],
"_source": {
"include": [
"id",
"name",
"birth"
]
},
"size": 1
}
}
}
}
}
}