自 1.0 版以来,聚合框架一直是 Elasticsearch 重要的一部分,多年来,它进行了优化,修复,甚至进行了一些大修。自Elasticsearch 7.0 版本以来,Elasticsearch 中已添加了许多新的聚合,例如 rare_terms,top_metrics 或 auto_date_histogram 聚合。在此博客文章中,我们将探索其中的一些,并仔细研究它们可以为你做什么。为了测试这些新的aggs,我们将在 Elasticsearch 7.9 部署中设置样本数据集。
以下文档可能代表电子商务用例,其中用户单击产品并检索产品详细信息。当然,它缺少许多细节,例如单个用户的会话 ID,因此你可以启动和监视会话,甚至走得更远,并利用 transforms 来获得对数据的进一步洞察。这篇文章仍然很简单,以确保理解所有概念。
在命令行中使用 Kibana 中的 Discover 或 cURL 从命令行中导入例数据:
PUT website-analytics/_bulk?refresh
{"index":{}}
{"product_id":"123","@timestamp":"2020-10-01T11:11:23.000Z","price":12.34,"response_time_ms":242}
{"index":{}}
{"product_id":"456","@timestamp":"2020-10-02T12:14:00.000Z","price":20.58,"response_time_ms":98}
{"index":{}}
{"product_id":"789","@timestamp":"2020-10-03T13:15:00.000Z","price":34.16,"response_time_ms":123}
{"index":{}}
{"product_id":"123","@timestamp":"2020-10-02T14:16:00.000Z","price":12.34,"response_time_ms":465}
{"index":{}}
{"product_id":"123","@timestamp":"2020-10-02T14:18:00.000Z","price":12.34,"response_time_ms":158}
{"index":{}}
{"product_id":"123","@timestamp":"2020-10-03T15:17:00.000Z","price":12.34,"response_time_ms":168}
{"index":{}}
{"product_id":"789","@timestamp":"2020-10-06T15:17:00.000Z","price":34.16,"response_time_ms":220}
{"index":{}}
{"product_id":"789","@timestamp":"2020-10-10T15:17:00.000Z","price":34.16,"response_time_ms":99}
上面的数据展示的是一个时间系列数据,但是每天都有一个数据的。
Auto-bucketing aggregations
这些类型的聚合会自动更改定义存储桶的日期。 当你进行基于时间的汇总时,通常会根据时间间隔(例如1d)来定义存储分区。 但是,有时你不知道数据的性质,我们只需仅从用户角度讲告诉期望的存储桶数会更容易些。
这是以下两个新聚合起作用的地方。
auto_date_histogram Aggregation
auto_date_histogram 聚合在日期字段上运行,并允许你配置期望返回的存储桶数。 让我们在小型数据集上尝试一下:
POST website-analytics/_search?size=0
{
"aggs": {
"views_over_time": {
"auto_date_histogram": {
"field": "@timestamp",
"buckets": 3
}
}
}
}
运行上面的聚合,生产的结果为:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"views_over_time" : {
"buckets" : [
{
"key_as_string" : "2020-10-01T00:00:00.000Z",
"key" : 1601510400000,
"doc_count" : 7
},
{
"key_as_string" : "2020-10-08T00:00:00.000Z",
"key" : 1602115200000,
"doc_count" : 1
}
],
"interval" : "7d"
}
}
}
我们再接着运行如下的聚合:
POST website-analytics/_search?size=0
{
"aggs": {
"views_over_time": {
"auto_date_histogram": {
"field": "@timestamp",
"buckets": 10
}
}
}
}
上面的命令生产的结果为:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"views_over_time" : {
"buckets" : [
{
"key_as_string" : "2020-10-01T00:00:00.000Z",
"key" : 1601510400000,
"doc_count" : 1
},
{
"key_as_string" : "2020-10-02T00:00:00.000Z",
"key" : 1601596800000,
"doc_count" : 3
},
{
"key_as_string" : "2020-10-03T00:00:00.000Z",
"key" : 1601683200000,
"doc_count" : 2
},
{
"key_as_string" : "2020-10-04T00:00:00.000Z",
"key" : 1601769600000,
"doc_count" : 0
},
{
"key_as_string" : "2020-10-05T00:00:00.000Z",
"key" : 1601856000000,
"doc_count" : 0
},
{
"key_as_string" : "2020-10-06T00:00:00.000Z",
"key" : 1601942400000,
"doc_count" : 1
},
{
"key_as_string" : "2020-10-07T00:00:00.000Z",
"key" : 1602028800000,
"doc_count" : 0
},
{
"key_as_string" : "2020-10-08T00:00:00.000Z",
"key" : 1602115200000,
"doc_count" : 0
},
{
"key_as_string" : "2020-10-09T00:00:00.000Z",
"key" : 1602201600000,
"doc_count" : 0
},
{
"key_as_string" : "2020-10-10T00:00:00.000Z",
"key" : 1602288000000,
"doc_count" : 1
}
],
"interval" : "1d"
}
}
}
运行这两个查询将显示返回的间隔基于请求的存储桶数。 如果要求是3桶,则每周应为1桶,而如果是10桶,则每天应为1桶。
如果需要最小间隔,也可以配置此最小间隔,请参见 auto_date_histogram 文档。
variable_width_histogram Aggregation
可变宽度直方图允许动态创建预配置数量的存储桶。 最重要的是,与常规直方图聚合的固定宽度相比,这些存储桶的宽度可变。
POST website-analytics/_search?size=0
{
"aggs": {
"prices": {
"variable_width_histogram": {
"field": "price",
"buckets": 3
}
}
}
}
由于我们的数据集中只有三个不同的价格,因此最小/最大/键值是相同的。 但是,你可以尝试使用两个存储桶,然后看到一个存储桶现在具有不同的值。运行上面的聚合:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"prices" : {
"buckets" : [
{
"min" : 12.34000015258789,
"key" : 12.34000015258789,
"max" : 12.34000015258789,
"doc_count" : 4
},
{
"min" : 20.579999923706055,
"key" : 20.579999923706055,
"max" : 20.579999923706055,
"doc_count" : 1
},
{
"min" : 34.15999984741211,
"key" : 34.15999984741211,
"max" : 34.15999984741211,
"doc_count" : 3
}
]
}
}
}
假如我们把 buckets 设置为2,那么就是这样的结果:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"prices" : {
"buckets" : [
{
"min" : 12.34000015258789,
"key" : 13.988000106811523,
"max" : 20.579999923706055,
"doc_count" : 5
},
{
"min" : 34.15999984741211,
"key" : 34.15999984741211,
"max" : 34.15999984741211,
"doc_count" : 3
}
]
}
}
另外,请记住:bucket bounds are approximate。
一个用例可能是一个电子商务应用程序,你希望在其中将价格段显示为多面导航的一部分。 但是,使用此选项会使你的网站导航对异常值相当敏感,因此请在执行此操作之前考虑考虑使用类别过滤器。
Aggregations on strings
rare_terms Aggregation
作为 Elastic Stack 用户,你可能已经使用过 terms aggregation,并出现过错误。通常情况下,terms aggregation 将返回数据集中出现次数最多的字词。 你可以更改排序以返回找到最少的术语。 但是,这将带来无穷无尽的错误,因此,结果可能是一个近似值,因为该数据是在整个群集的多个分片上收集的。 这是因为 Elasticsearch 试图阻止将所有数据从不同的分片复制到单个节点,因为这样做既昂贵又缓慢。
与 terms aggregation 相比,rear_terms 聚合尝试通过使用不同的实现来规避这些问题。 即使这仍在进行近似计数,稀有项聚合也具有定义明确的有界误差。
要找出在上述数据集中索引最少的产品ID,请尝试以下操作
POST website-analytics/_search?size=0
{
"aggs": {
"rarest_product_ids": {
"rare_terms": {
"field": "product_id.keyword"
}
}
}
}
上面的命令返回的结果是:
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"rarest_product_ids" : {
"buckets" : [
{
"key" : "456",
"doc_count" : 1
}
]
}
}
}
你还可以使用 max_doc_count(与术语聚合的 min_doc_count 相反)并更改要返回的存储桶数。
string_stats Aggregation
如何获取有关数据中字符串字段值的一些统计信息? 我们去尝试一下 string_stats 聚合:
POST website-analytics/_search?size=0
{
"aggs": {
"rarest_product_ids": {
"string_stats": {
"field": "product_id.keyword",
"show_distribution" : true
}
}
}
}
上面的命令显示的结果是:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"rarest_product_ids" : {
"count" : 8,
"min_length" : 3,
"max_length" : 3,
"avg_length" : 3.0,
"entropy" : 2.9906015629507223,
"distribution" : {
"1" : 0.16666666666666666,
"2" : 0.16666666666666666,
"3" : 0.16666666666666666,
"7" : 0.125,
"8" : 0.125,
"9" : 0.125,
"4" : 0.041666666666666664,
"5" : 0.041666666666666664,
"6" : 0.041666666666666664
}
}
}
}
这将返回有关该字段中字符串的最小/最大/平均长度的统计信息,但是通过添加 show_distribution 参数,你还将看到找到的每个字符的分布。
这是一种快速检查数据以发现异常值的简便方法,例如,索引可能会被错误索引,例如产品 ID 过长或过短。 同样,返回的 Shannon Entropy 可用于查找 DNS 数据渗透尝试之类的目的。
Metrics based aggregations
让我们深入研究第二组聚合,它们是在桶聚合之上的数值字段指标计算。
top_metrics Aggregation
你可能已经知道 top_hits 聚合,它将返回完整的匹配,包括其来源。 但是,如果你只对单个值感兴趣,并希望以此排序,请查看top_metrics 聚合。 如果不需要整个文档,则此聚合将比 top_hits 聚合快很多,通常用于从每个存储桶中检索最新值。
在我们的点击流数据集中,你可能会对最新点击事件的价格感兴趣。
POST website-analytics/_search
{
"size": 0,
"aggs": {
"tm": {
"top_metrics": {
"metrics": {"field": "price"},
"sort": {"@timestamp": "desc"}
}
}
}
}
上面返回如下的结果:
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"tm" : {
"top" : [
{
"sort" : [
"2020-10-10T15:17:00.000Z"
],
"metrics" : {
"price" : 34.15999984741211
}
}
]
}
}
}
排序还支持 _score 或地理距离。 此外,你可以指定多个指标,因此可以向指标字段添加另一个字段,然后需要将其变成数组。
boxplot Aggregation
boxplot 聚合完全按照名称所说的进行操作-提供 box plot:
GET website-analytics/_search
{
"size": 0,
"aggs": {
"by_date": {
"date_histogram": {
"field": "@timestamp",
"calendar_interval": "day",
"min_doc_count": 1
},
"aggs": {
"load_time_boxplot": {
"boxplot": {
"field": "price"
}
}
}
}
}
}
上面的查询返回的结果为:
{
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"by_date" : {
"buckets" : [
{
"key_as_string" : "2020-10-01T00:00:00.000Z",
"key" : 1601510400000,
"doc_count" : 1,
"load_time_boxplot" : {
"min" : 12.34000015258789,
"max" : 12.34000015258789,
"q1" : 12.34000015258789,
"q2" : 12.34000015258789,
"q3" : 12.34000015258789
}
},
{
"key_as_string" : "2020-10-02T00:00:00.000Z",
"key" : 1601596800000,
"doc_count" : 3,
"load_time_boxplot" : {
"min" : 12.34000015258789,
"max" : 20.579999923706055,
"q1" : 12.34000015258789,
"q2" : 12.34000015258789,
"q3" : 18.519999980926514
}
},
{
"key_as_string" : "2020-10-03T00:00:00.000Z",
"key" : 1601683200000,
"doc_count" : 2,
"load_time_boxplot" : {
"min" : 12.34000015258789,
"max" : 34.15999984741211,
"q1" : 12.34000015258789,
"q2" : 23.25,
"q3" : 34.15999984741211
}
},
{
"key_as_string" : "2020-10-06T00:00:00.000Z",
"key" : 1601942400000,
"doc_count" : 1,
"load_time_boxplot" : {
"min" : 34.15999984741211,
"max" : 34.15999984741211,
"q1" : 34.15999984741211,
"q2" : 34.15999984741211,
"q3" : 34.15999984741211
}
},
{
"key_as_string" : "2020-10-10T00:00:00.000Z",
"key" : 1602288000000,
"doc_count" : 1,
"load_time_boxplot" : {
"min" : 34.15999984741211,
"max" : 34.15999984741211,
"q1" : 34.15999984741211,
"q2" : 34.15999984741211,
"q3" : 34.15999984741211
}
}
]
}
}
}
上面的查询返回每天的 box plot,其中每日存储桶中有数据。
我们将跳过 t-test 聚合,因为此处的超小型数据集不允许任何有用的聚合请求。 要查看此聚合的价值,你需要一个数据集,在其中假设可以通过统计假设发现的行为变化。
Pipeline aggregations
接下来,在称为管道聚合的聚合之上的聚合。 去年增加了不少这类的聚合。
cumulative_cardinality Aggregation
这是用于查找数据集中新项目数的有用聚合。
GET website-analytics/_search
{
"size": 0,
"aggs": {
"by_day": {
"date_histogram": {
"field": "@timestamp",
"calendar_interval": "day"
},
"aggs": {
"distinct_products": {
"cardinality": {
"field": "product_id.keyword"
}
},
"total_new_products": {
"cumulative_cardinality": {
"buckets_path": "distinct_products"
}
}
}
}
}
}
上面查询返回的结果是:
{
"took" : 9,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"by_day" : {
"buckets" : [
{
"key_as_string" : "2020-10-01T00:00:00.000Z",
"key" : 1601510400000,
"doc_count" : 1,
"distinct_products" : {
"value" : 1
},
"total_new_products" : {
"value" : 1
}
},
{
"key_as_string" : "2020-10-02T00:00:00.000Z",
"key" : 1601596800000,
"doc_count" : 3,
"distinct_products" : {
"value" : 2
},
"total_new_products" : {
"value" : 2
}
},
{
"key_as_string" : "2020-10-03T00:00:00.000Z",
"key" : 1601683200000,
"doc_count" : 2,
"distinct_products" : {
"value" : 2
},
"total_new_products" : {
"value" : 3
}
},
{
"key_as_string" : "2020-10-04T00:00:00.000Z",
"key" : 1601769600000,
"doc_count" : 0,
"distinct_products" : {
"value" : 0
},
"total_new_products" : {
"value" : 3
}
},
{
"key_as_string" : "2020-10-05T00:00:00.000Z",
"key" : 1601856000000,
"doc_count" : 0,
"distinct_products" : {
"value" : 0
},
"total_new_products" : {
"value" : 3
}
},
{
"key_as_string" : "2020-10-06T00:00:00.000Z",
"key" : 1601942400000,
"doc_count" : 1,
"distinct_products" : {
"value" : 1
},
"total_new_products" : {
"value" : 3
}
},
{
"key_as_string" : "2020-10-07T00:00:00.000Z",
"key" : 1602028800000,
"doc_count" : 0,
"distinct_products" : {
"value" : 0
},
"total_new_products" : {
"value" : 3
}
},
{
"key_as_string" : "2020-10-08T00:00:00.000Z",
"key" : 1602115200000,
"doc_count" : 0,
"distinct_products" : {
"value" : 0
},
"total_new_products" : {
"value" : 3
}
},
{
"key_as_string" : "2020-10-09T00:00:00.000Z",
"key" : 1602201600000,
"doc_count" : 0,
"distinct_products" : {
"value" : 0
},
"total_new_products" : {
"value" : 3
}
},
{
"key_as_string" : "2020-10-10T00:00:00.000Z",
"key" : 1602288000000,
"doc_count" : 1,
"distinct_products" : {
"value" : 1
},
"total_new_products" : {
"value" : 3
}
}
]
}
}
}
通过上面的查询,你可以计算出每天有多少新产品和未知产品被访问过,并创建了这些产品的计数。 这可能会帮助你在电子商务环境中确定你的新产品是否得到了真正的关注,或者你的畅销书是否位居榜首,你可能应该更改营销方式。
normalize Aggregation
让我们尝试概述一下,哪一天的流量百分比最高,其中100%是与查询匹配的全部数据。
GET website-analytics/_search
{
"size": 0,
"aggs": {
"by_day": {
"date_histogram": {
"field": "@timestamp",
"calendar_interval": "day"
},
"aggs": {
"normalize": {
"normalize": {
"buckets_path": "_count",
"method": "percent_of_sum"
}
}
}
}
}
}
上面返回的结果是:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"by_day" : {
"buckets" : [
{
"key_as_string" : "2020-10-01T00:00:00.000Z",
"key" : 1601510400000,
"doc_count" : 1,
"normalize" : {
"value" : 0.125
}
},
{
"key_as_string" : "2020-10-02T00:00:00.000Z",
"key" : 1601596800000,
"doc_count" : 3,
"normalize" : {
"value" : 0.375
}
},
{
"key_as_string" : "2020-10-03T00:00:00.000Z",
"key" : 1601683200000,
"doc_count" : 2,
"normalize" : {
"value" : 0.25
}
},
{
"key_as_string" : "2020-10-04T00:00:00.000Z",
"key" : 1601769600000,
"doc_count" : 0,
"normalize" : {
"value" : 0.0
}
},
{
"key_as_string" : "2020-10-05T00:00:00.000Z",
"key" : 1601856000000,
"doc_count" : 0,
"normalize" : {
"value" : 0.0
}
},
{
"key_as_string" : "2020-10-06T00:00:00.000Z",
"key" : 1601942400000,
"doc_count" : 1,
"normalize" : {
"value" : 0.125
}
},
{
"key_as_string" : "2020-10-07T00:00:00.000Z",
"key" : 1602028800000,
"doc_count" : 0,
"normalize" : {
"value" : 0.0
}
},
{
"key_as_string" : "2020-10-08T00:00:00.000Z",
"key" : 1602115200000,
"doc_count" : 0,
"normalize" : {
"value" : 0.0
}
},
{
"key_as_string" : "2020-10-09T00:00:00.000Z",
"key" : 1602201600000,
"doc_count" : 0,
"normalize" : {
"value" : 0.0
}
},
{
"key_as_string" : "2020-10-10T00:00:00.000Z",
"key" : 1602288000000,
"doc_count" : 1,
"normalize" : {
"value" : 0.125
}
}
]
}
}
}
这将为每个存储桶返回其他信息:每个存储桶中找到的文档数量与搜索返回的总文档数的百分比。
你可能需要查看 normalize aggregation documentation,因为可以从中选择更多方法值,例如均值或范围内的重新定标。
moving percentiles Aggregation
该管道聚合在百分位数聚合之上工作,并使用滑动窗口计算累积百分位数。
GET website-analytics/_search
{
"size": 0,
"aggs": {
"by_day": {
"date_histogram": {
"field": "@timestamp",
"calendar_interval": "day"
},
"aggs": {
"response_time": {
"percentiles": {
"field": "response_time_ms",
"percents": [ 75, 99 ]
}
},
"moving_pct": {
"moving_percentiles": {
"buckets_path": "response_time",
"window": 2
}
}
}
}
}
}
上面的查询返回的结果是:
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"by_day" : {
"buckets" : [
{
"key_as_string" : "2020-10-01T00:00:00.000Z",
"key" : 1601510400000,
"doc_count" : 1,
"response_time" : {
"values" : {
"75.0" : 242.0,
"99.0" : 242.0
}
}
},
{
"key_as_string" : "2020-10-02T00:00:00.000Z",
"key" : 1601596800000,
"doc_count" : 3,
"response_time" : {
"values" : {
"75.0" : 388.25,
"99.0" : 465.0
}
},
"moving_pct" : {
"values" : {
"75.0" : 242.0,
"99.0" : 242.0
}
}
},
{
"key_as_string" : "2020-10-03T00:00:00.000Z",
"key" : 1601683200000,
"doc_count" : 2,
"response_time" : {
"values" : {
"75.0" : 168.0,
"99.0" : 168.0
}
},
"moving_pct" : {
"values" : {
"75.0" : 353.5,
"99.0" : 465.0
}
}
},
{
"key_as_string" : "2020-10-04T00:00:00.000Z",
"key" : 1601769600000,
"doc_count" : 0,
"response_time" : {
"values" : {
"75.0" : null,
"99.0" : null
}
},
"moving_pct" : {
"values" : {
"75.0" : 242.25,
"99.0" : 465.0
}
}
},
{
"key_as_string" : "2020-10-05T00:00:00.000Z",
"key" : 1601856000000,
"doc_count" : 0,
"response_time" : {
"values" : {
"75.0" : null,
"99.0" : null
}
},
"moving_pct" : {
"values" : {
"75.0" : 168.0,
"99.0" : 168.0
}
}
},
{
"key_as_string" : "2020-10-06T00:00:00.000Z",
"key" : 1601942400000,
"doc_count" : 1,
"response_time" : {
"values" : {
"75.0" : 220.0,
"99.0" : 220.0
}
},
"moving_pct" : {
"values" : {
"75.0" : null,
"99.0" : null
}
}
},
{
"key_as_string" : "2020-10-07T00:00:00.000Z",
"key" : 1602028800000,
"doc_count" : 0,
"response_time" : {
"values" : {
"75.0" : null,
"99.0" : null
}
},
"moving_pct" : {
"values" : {
"75.0" : 220.0,
"99.0" : 220.0
}
}
},
{
"key_as_string" : "2020-10-08T00:00:00.000Z",
"key" : 1602115200000,
"doc_count" : 0,
"response_time" : {
"values" : {
"75.0" : null,
"99.0" : null
}
},
"moving_pct" : {
"values" : {
"75.0" : 220.0,
"99.0" : 220.0
}
}
},
{
"key_as_string" : "2020-10-09T00:00:00.000Z",
"key" : 1602201600000,
"doc_count" : 0,
"response_time" : {
"values" : {
"75.0" : null,
"99.0" : null
}
},
"moving_pct" : {
"values" : {
"75.0" : null,
"99.0" : null
}
}
},
{
"key_as_string" : "2020-10-10T00:00:00.000Z",
"key" : 1602288000000,
"doc_count" : 1,
"response_time" : {
"values" : {
"75.0" : 99.0,
"99.0" : 99.0
}
},
"moving_pct" : {
"values" : {
"75.0" : null,
"99.0" : null
}
}
}
]
}
}
}
这里要展开一点,让我们开始吧。 按天进行存储后,百分位数聚合将计算每天存储桶的百分位数。 然后,moving_percentiles 管道 agg 取前两个存储桶,并从中计算出移动平均值。 请注意,如果你还想包含当前存储桶,则可以通过使用 shift 参数来更改应使用哪些存储桶的行为。
pipeline inference Aggregation
我们将跳过推理存储桶聚合,因为计划很快发布一个博客文章来解释这种聚合。 激发您的胃口:你可以针对父级存储桶汇总的结果运行经过预训练的模型。 敬请关注!
Support for the histogram
field type
严格来说,这不是聚合,但是聚合受此数据类型的影响,因此值得一提。
你可能已经迷失了 histogram field type,它允许你存储预聚合的数值数据-例如,在 Elastic Observability 中广泛使用了该数据。 此特殊字段类型支持聚合的子集,您会发现一些尚不支持的聚合...。 但是,还有更多工作要做以支持这些。
Support for geo_shape
in geo aggregations
再次严格地说,这不是单一聚合,而是向前迈出的一大步,因此值得一提。
除了 geo_point 字段类型之外,还进行了巨大的投资来使 geo_bounds,geo_tile,geo_hashgrid 和 geo_centroid 聚合与 geo_shape 字段类型一起使用。