GET /cars/transactions/_search
{
"size" : 0,
"aggs" : {
"colors" : {
"terms" : {
"field" : "color",
"order": {
"avg_price" : "desc"
}
},
"aggs": {
"avg_price": {
"avg": {"field": "price"}
}
}
}
}
}
这是官网的一个例子,按照颜色分组,统计不同颜色汽车销售额的平均值
结果如下:
"aggregations": {
"colors": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "red",
"doc_count": 4,
"avg_price": {
"value": 32500
}
},
{
"key": "green",
"doc_count": 2,
"avg_price": {
"value": 21000
}
},
{
"key": "blue",
"doc_count": 2,
"avg_price": {
"value": 20000
}
}
]
}
}
我现在想在这个基础上对每种颜色汽车销售额均值再做均值,最大值,最小值统计,请问有何好的办法
{
"size" : 0,
"aggs" : {
"colors" : {
"terms" : {
"field" : "color",
"order": {
"avg_price" : "desc"
}
},
"aggs": {
"avg_price": {
"avg": {"field": "price"}
}
}
}
}
}
这是官网的一个例子,按照颜色分组,统计不同颜色汽车销售额的平均值
结果如下:
"aggregations": {
"colors": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "red",
"doc_count": 4,
"avg_price": {
"value": 32500
}
},
{
"key": "green",
"doc_count": 2,
"avg_price": {
"value": 21000
}
},
{
"key": "blue",
"doc_count": 2,
"avg_price": {
"value": 20000
}
}
]
}
}
我现在想在这个基础上对每种颜色汽车销售额均值再做均值,最大值,最小值统计,请问有何好的办法
2 个回复
rochy - rochy_he
赞同来自: Sunsy 、dlliwei
PS:以下代码未经测试
ziyou - 一个学习ELK的Java程序员
赞同来自:
https://elasticsearch.cn/article/13435