elasticsearch-aggregations

指标聚合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既可。


文章作者: EvanZhou
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 EvanZhou !
 上一篇
shiro基础 shiro基础
shiro 架构 Authentication: 身份认证/登录,是一个可扩展点,可以自定义实现;可以使用认证 策略(Authentication Strategy),即什么情况下算用户认证通过了; Authorization: 权限验
2019-12-19
下一篇 
java8新特性 java8新特性
stream流式APIstream 的思想是内部迭代,for-each是外部迭代。流只能使用一次。 stream 优势: 并行 能充分利用多核 能直观描述数据的操作,代码可读性更高 创建流的方式// 1、创建stream的
2019-11-16
  目录