aggregations聚合,相当于SQL中的group by,但是功能更强大。
es聚合分为四种方式:指标聚合,桶聚合,矩阵聚合,管道聚合。
常用的为前两种,指标聚合,桶聚合。
1:指标聚合
指标聚合:Metrics Aggregations,类似于SQL中常见的一些统计方法 COUNT() 、 SUM() 、 MAX() 等。
terms相当于分组后统计各组的count()结果
查询:
"aggs": {
"test" : {
"terms" : {
"field" : "data.keyword"
}
}
}
结果:
{
"aggregations": {
"test": {
"doc_count_error_upper_bound": 7109,
"sum_other_doc_count": 11029748,
"buckets": [
{
"key": "data1",
"doc_count": 30304
},
{
"key": "data2",
"doc_count": 20846
},
{
"key": "data13",
"doc_count": 9466