百分数桶聚合(Percentiles Bucket Aggregation)
警告:此功能是实验性的,可能会在未来的版本中完全更改或删除。Elastic将采取最大的努力来解决任何的问题,但是实验功能不受SLA官方功能的支持。
{
"percentiles_bucket": {
"buckets_path": "the_sum"
}
}
POST /sales/_search
{
"size": 0,
"aggs" : {
"sales_per_month" : {
"date_histogram" : {
"field" : "date",
"interval" : "month"
},
"aggs": {
"sales": {
"sum": {
"field": "price"
}
}
}
},
"percentiles_monthly_sales": {
"percentiles_bucket": {
"buckets_path": "sales_per_month>sales", #1
"percents": [ 25.0, 50.0, 75.0 ] #2
}
}
}
}
{
"took": 11,
"timed_out": false,
"_shards": ...,
"hits": ...,
"aggregations": {
"sales_per_month": {
"buckets": [
{
"key_as_string": "2015/01/01 00:00:00",
"key": 1420070400000,
"doc_count": 3,
"sales": {
"value": 550.0
}
},
{
"key_as_string": "2015/02/01 00:00:00",
"key": 1422748800000,
"doc_count": 2,
"sales": {
"value": 60.0
}
},
{
"key_as_string": "2015/03/01 00:00:00",
"key": 1425168000000,
"doc_count": 2,
"sales": {
"value": 375.0
}
}
]
},
"percentiles_monthly_sales": {
"values" : {
"25.0": 375.0,
"50.0": 375.0,
"75.0": 550.0
}
}
}
}
百分数是精确计算的,不是近似值(与百分数指标不同)。这意味着在丢弃数据之前,实现会在内存中维护一个有序的数据列表来计算百分数。如果你尝试在数百万的数据点中计算一个百分数的percentiles_bucket,可能会遇到内存压力问题。