用途:用于执行组件的max()
、min()
、avg()
、sum()
四个聚合函数。
依赖类:\x\Elasticsearch
方法名:aggs()
参数:无
返回值:失败返回false
,成功返回一个一维数组。
使用示例:
$Elasticsearch = new \x\Elasticsearch();
$where = [
['title', '=', '骑士队', 'must'],
['title', '=', '利夫兰', 'filter'],
];
// 支持同时使用多个聚合函数
$res = $Elasticsearch->table('shop')->where($where)
->max('age')
->min('age')
->avg('age')
->sum('age')
->aggs();
var_dump($res);
返回结果:
array(1) {
["max_age"] => 18,
["min_age"] => 1,
["avg_age"] => 15.6,
["sum_age"] => 201,
}
提示:返回字段的结果为:聚合函数名_查询字段
。