我正在研究Elasticsearch聚合,我希望获得一个聚合所有记录值的值。我可以使用“Range> = 0”聚合作弊,但是有更惯用的方法吗?
我的kludgy查询是:
json_encode
答案 0 :(得分:1)
ES已将此构建到"统计数据"为你聚合,使用" sum"结果
GET devdev/alert/_search
{
"size": 0,
"aggs": {
"ag1": {
"stats": {
"field": "price"
}
}
}
}
结果:
{
"took": 483,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 4129196,
"max_score": 0,
"hits": []
},
"aggregations": {
"ag1": {
"count": 4119334,
"min": -1,
"max": 7004,
"avg": 5.29581966405249,
"sum": 21815250
}
}
}