1.avg 平均
localhost:9200/account/_search
{
"aggs":{
"avg_id":{ 自定义名字
"avg":{ 关键字
"field":"id" 字段
}
}
},
"size":0
}
结果:
{
"took": 15,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 990,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"avg_id": {
"value": 496.7030303030303
}
}
}
2.cardinality 基数
相当于sql group by之后的总条数
{
"aggs" : {
"type_count" : {
"cardinality" : {
"field" : "id"
}
}
},
"size":0
}
3.extended_stats 扩展统计
返回max min avg count sum sum_of_squares variance(方差) std_deviation(偏差) std_deviation_bounds(偏差边界,平均值+-两个偏差)
{
"size": 0,
"aggs": {
"e-stats": {
"extended_stats": {
"field": "id"
}
}
}
}
{
...
"aggregations": {
"grades_stats": {
"count": 2,
"min": 50.0,
"max": 100.0,
"avg": 75.0,
"sum": 150.0,
"sum_of_squares": 12500.0,
"variance": 625.0,
"std_deviation": 25.0,
"std_deviation_bounds": {
"upper": 125.0,
"lower": 25.0
}
}
}
}
4.max 最大
{
"aggs": {
"max_id": {
"max": {
"field": "id"
}
}
},
"size":0
}
5.min 最小
{
"aggs": {
"min_id": {
"min": {
"field": "id"
}
}
},
"size":0
}
6.percentiles 百分位
评估当前数值分布情况
在对应百分位的值,默认【1,5,25,50,75,95,99】
{
"aggs": {
"max_id": {
"percentiles": {
"field": "num",
"percents":[10] //返回特定百分位的值
}
}
},
"size":0
}
7.percentile_ranks 百分位排名
当前数值中处于哪一个范围内,查它的 rank,发现是100,那么说明有100%的数值都在10以内。
{
"aggs": {
"max_id": {
"percentile_ranks ": {
"field": "num",
"values":[10,50] //返回特定百分位的值
}
}
},
"size":0
}
8.stats 统计
返回 min max sum count avg
{
"aggs": {
"min_id": {
"stats": {
"field": "num"
}
}
},
"size":0
}
9.sum 求和
{
"aggs": {
"max_id": {
"sum": {
"field": "num"
}
}
},
"size":0
}
10.value_count 个数统计
{
"aggs": {
"max_id": {
"sum": {
"field": "num"
}
}
},
"size":0
}
网友评论