聚合分析的格式:
"aggregations" : {
"<aggregation_name>" : {
"<aggregation_type>" : {
<aggregation_body>
}
[,"meta" : { [<meta_data_body>] } ]?
[,"aggregations" : { [<sub_aggregation>]+ } ]?
}
[,"<aggregation_name_2>" : { ... } ]*
}
举个栗子-------------------------------
GET test_index/doc/_search { "size":0 "aggs": { #聚合关键字 "avg_age": { #聚合的名字 "max": { #聚合分析的类型 "field": "age" #body }}}}
聚合分析有四种:
metrics,指标分析聚合
bucket,分桶类型
pipeline,管道分析
matrix,矩阵分析
SELECT COUNT(color) FROM table GROUP BY color # GROUP BY相当于做分桶(bucket)的工作,COUNT是统计指标(metrics)。
- Metrics
单值分析
-
min 返回数值类字段的最小值
View Code
GET test_index/_search { "size": 0, "aggs": { "min_age": { "min": { "field": "age" } } } } ---> "aggregations": { "min_age": { "value": 10 } }