es查询

以某个字段分组 时间排序取前2

{
"query": {
"bool": {
"must": [
{
"terms": {
"author_id": ["64124271277","75813696626","53242954156","56284938462"]

}
}
]
}
},
"size": 0,
"aggs": {
"groupby-fiel": {
"terms": {
"field": "author_id",
"size": 100
},
"aggs": {
"top-number": {
"top_hits": {
"size": 2,
"sort": [
{
"ctime": {
"order": "desc"
}
}
]
}
}
}
}
}
}

aggregation 分类 整体分为3大类 

1.bucketing 桶分聚合

2.metric 指标聚合

3.pipeline 管道聚合

top 前 n 

原文地址:https://www.cnblogs.com/yuguohua/p/12697677.html