##################es聚合分析查询###################
es中聚合的分类 有Bucket aggregation 桶聚合(类似于mysql 的group by 分组查询) 有metric aggregation 数学函数聚合, (类似mysql的聚合函数 max min avg sum等) pipeline aggregation 对其他的聚合结果进行二次聚合 matrik aggregation 支持对多字段的操作并提供一个结果矩阵
按照手机品牌进行桶聚合
GET goods/_search
{
"query": {
"term": {
"categoryName.keyword": {
"value": "手机"
}
}
}
,"aggs": {
"手机分类": {
"terms": {
"field": "brandName.keyword"
}
}
}
}
GET goods
求出每个手机的最高价格最低价格平均价格
GET goods/_search
{
"query": {
"term": {
"categoryName.keyword": {
"value": "手机"
}
}
},
"aggs": {
"手机分类": {
"terms": {
"field": "brandName.keyword"
},
"aggs": {
"max": {
"max": {
"field": "price"
}
},
"min": {
"min": {
"field": "price"
}
},
"avg": {
"avg": {
"field": "price"
}
}
}
}
}
}
GET goods/_search
# 聚合统计
GET goods/_search
{
"aggs": {
"品牌分类": {
"terms": {
"field": "brandName.keyword"
},
"aggs": {
"价格统计信息": {
"stats": {
"field": "price"
}
}
}
}
}
}