例子 GET /collect_data_store_goods_fact*/_search { "query": { "match_all": {} }, "size": 0, "aggs": {
例子
GET /collect_data_store_goods_fact*/_search
{
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"brand":{
"terms": {
"field": "orgId",
"size": 2,
"order": {
"or_totalSaleGoodsAmountSum": "desc"
}
},
"aggs": {
"or_totalSaleGoodsAmountSum": {
"sum": {
"field": "store_goods_totalSaleGoodsAmount"
}
}
}
},
"stats_monthly_sales": {
"stats_bucket": {
"buckets_path": "brand>or_totalSaleGoodsAmountSum"
}
},
"avg_stately_age" : {
"avg_bucket": {
"buckets_path": "brand>or_totalSaleGoodsAmountSum"
}
},
"store_goods_totalSaleGoodsAmountALL": {
"sum": {
"field": "store_goods_totalSaleGoodsAmount"
}
}
}
}
执行结果
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 30,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"store_goods_totalSaleGoodsAmountALL" : {
"value" : 1.6650087E7
},
"brand" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 12,
"buckets" : [
{
"key" : 13274,
"doc_count" : 17,
"or_totalSaleGoodsAmountSum" : {
"value" : 1.6112652E7
}
},
{
"key" : 13278,
"doc_count" : 1,
"or_totalSaleGoodsAmountSum" : {
"value" : 299700.0
}
}
]
},
"stats_monthly_sales" : {
"count" : 2,
"min" : 299700.0,
"max" : 1.6112652E7,
"avg" : 8206176.0,
"sum" : 1.6412352E7
},
"avg_stately_age" : {
"value" : 8206176.0
}
}
}
因为 bucket 似乎默认是 返回10个 桶的,除非指定 size 将所有桶都 返回出来否则计算 桶的平均值 是 用 显示出来的 桶的数据/size 的。
也就是 说 avg_bucket 并不能 获取到 分组之后 所有桶的 平均值了。
--结束END--
本文标题: elasticsearch 聚合之后获取桶的平均值avg_bucket或者stats_bucket
本文链接: https://lsjlt.com/news/2245.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0