度量聚合:求字段的平均值,最小值,最大值,总和等
桶聚合:将文档分成不同的桶,桶的划分可以根据字段的值,范围,日期间隔
管道聚合:在其他聚合的结果上执行进一步计算
聚集被命名为 avg_age
POST user/_search
{
"query": {
"match_all": {}
},
"aggs": {"avg_age": {"avg": {"field": "age"}}}
}
POST user/_search
{
"query": {
"match_all": {}
},
"aggs": {"max_age": {"max": {"field": "age"}}}
}
POST user/_search
{
"query": {
"match_all": {}
},
"aggs": {"min_age": {"min": {"field": "age"}}}
}
POST user/_search
{
"query": {
"match_all": {}
},
"aggs": {"sum_age": {"sum": {"field": "age"}}}
}
按照某个字段的值进行聚合
POST user/_search
{
"query": {
"match_all": {}
},
"aggs": {"group_by_age": {"terms": {"field": "age"}}}
}
按照某个字段的范围进行聚合,from提供区间下界(包括),to提供区间上界(不包括)
POST user/_search
{
"query": {
"match_all": {}
},
"aggs": {
"age_ranges":{
"range": {
"field": "age",
"ranges": [
{ "to": 10 },
{ "from": 10, "to": 20 },
{ "from": 20 }
]
}
}
}
}
[1]https://www.elastic.co/guide/en/elasticsearch/reference/8.11/search-aggregations.html