#集合的分类:
#Bucket Agg:一些满足特定条件的集合,也就是分组
#Metric Agg:一些数学运算,对文档字段进行统计分析,count,avg,max,stats,cardinality(去重)等
#Pipeline Agg:对其他聚合的二次聚合
#Matrix Agg:支持对多个字段的操作并提供一个结果矩阵
#设置size为0,不返回数据,计算不同目的地的聚合统计
POST kibana_sample_data_flights/_search
{
"size": 0,
"aggs": {
"dests": {
"terms": {
"field": "Dest",
"size": 10
},
"aggs": {
"max_DistanceMiles": {
"max": {
"field": "DistanceMiles"
}
},
"price_stats": {
"stats": {
"field": "AvgTicketPrice"
}
}
}
}
}
}
GET kibana_sample_data_ecommerce/_mapping
POST kibana_sample_data_ecommerce/_search
{
"size": 0,
"aggs": {
"geoip_names": {
"terms": {
"field": "geoip.region_name",
"size": 10
}
}
}
}
#聚合分析比较频繁,文档写入也比较频繁时候,可以设置mappings.properties.字段.eager_global_ordinals为true,也就是一旦有数据写入的时候,term agg 就会提前加载。
# range/histrogram 分组
POST kibana_sample_data_flights/_search
{
"size": 0,
"aggs": {
"price_range": {
"range": {
"field": "AvgTicketPrice",
"ranges": [
{
"to": 200
},{
"from": 200,
"to": 400
},{
"from": 400,
"to": 600
},{
"from": 600,
"to": 800
},{
"from": 800,
"to": 1000
},{
"from": 1000,
"to":1200
}
]
}
}
}
}
POST kibana_sample_data_flights/_search
{
"size": 0,
"aggs": {
"price_histrogram": {
"histogram": {
"field": "AvgTicketPrice",
"interval":200,
"extended_bounds": {
"min": 0,
"max":1200
}
}
}
}
}
网友评论