指标聚合Metrics Aggregations
指标聚合分为单值聚合和多值聚合。
单值聚合
只返回一个指标
avg Aggregation
求平均值
Cardinality Aggregation
求基数,统计某个字段有多少个不同值。该值只是近似值,非准确值。可以设置精确阈值大小,以牺牲内存为代价,在该值一下,尽可能的准确。默认值是3000,支持的最大值是40000
Max Aggregation
统计最大值
Min Aggregation
统计最小值
Sum Aggregation
累加某个数值类型字段的总值。
Value Count Aggregation
对其它聚合文档中提取的value值计数。通常和其它单值聚合器一起使用。例如,当计算平均值时,统计参与计算的平均值的个数
Top Hits Aggregation
热门数据聚合
用于子聚合,统计每个bucket分组内的热门数据。
- from - The offset from the first result you want to fetch.
- size - The maximum number of top matching hits to return per bucket. By default the top three matching hits are returned.
- sort - How the top matching hits should be sorted. By default the hits are sorted by the score of the main query.
多值聚合
返回多个指标stats Aggregation
统计汇总,基于文档的某个值(可以是特定的数值型字段,也可以通过脚本计算而来),计算出一些统计信息(min、max、sum、count、avg5个值Extended Stats Aggregation
比stats多4个统计结果: 平方和、方差、标准差、平均值加/减两个标准差的区间Bucket Aggregations桶聚合
将数据分组,每一组就是一个桶,类似与sql的group by 分组。Terms Aggregation
Filters Aggregation
Filter Aggregation
Date Histogram Aggregation
Histogram Aggregation
常用于直方图统计
ps: 如果要返回没有数据的空桶,设置extended_bounds,并且min_doc_count必须为0;
只返回聚合结果
只返回聚合结果,不返回search查询结果会使我们的查询更加高效,只要设置查询size为0既可。