背景:
最近用es做数据检索,需要统计满足条件的zwk_zkrs字段的总和,特来记录一下
求和:
$params["body"]["aggs"]["total_zkrs"] = [ "sum" => [ "field" => "zwk_zkrs" ] ]; 求平均值 $params["body"]["aggs"]["avg_zkrs"] = [ "avg" => [ "field" => "zwk_zkrs" ] ];
注:total_zkrs为自定义内容,sum为求和参数,avg为求平均值,zwk_zkrs为求和字段,
参考文献:
https://www.elastic.co/guide/cn/elasticsearch/guide/current/_aggregation_test_drive.html