WARNING: Version 5.6 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Percentile Ranks Aggregation
editPercentile Ranks Aggregation
editA multi-value
metrics aggregation that calculates one or more percentile ranks
over numeric values extracted from the aggregated documents. These values
can be extracted either from specific numeric fields in the documents, or
be generated by a provided script.
Please see Percentiles are (usually) approximate and Compression for advice regarding approximation and memory use of the percentile ranks aggregation
Percentile rank show the percentage of observed values which are below certain value. For example, if a value is greater than or equal to 95% of the observed values it is said to be at the 95th percentile rank.
Assume your data consists of website load times. You may have a service agreement that 95% of page loads completely within 15ms and 99% of page loads complete within 30ms.
Let’s look at a range of percentiles representing load time:
{ "aggs" : { "load_time_outlier" : { "percentile_ranks" : { "field" : "load_time", "values" : [15, 30] } } } }
The response will look like this:
{ ... "aggregations": { "load_time_outlier": { "values" : { "15": 92, "30": 100 } } } }
From this information you can determine you are hitting the 99% load time target but not quite hitting the 95% load time target
Keyed Response
editBy default the keyed
flag is set to true
associates a unique string key with each bucket and returns the ranges as a hash rather than an array. Setting the keyed
flag to false
will disable this behavior:
POST bank/account/_search?size=0 { "aggs": { "balance_outlier": { "percentile_ranks": { "field": "balance", "values": [25000, 50000], "keyed": false } } } }
Response:
{ ... "aggregations": { "balance_outlier": { "values": [ { "key": 25000.0, "value": 48.537724935732655 }, { "key": 50000.0, "value": 99.85567010309278 } ] } } }
Script
editThe percentile rank metric supports scripting. For example, if our load times are in milliseconds but we want to specify values in seconds, we could use a script to convert them on-the-fly:
{ "aggs" : { "load_time_outlier" : { "percentile_ranks" : { "values" : [3, 5], "script" : { "lang": "painless", "source": "doc['load_time'].value / params.timeUnit", "params" : { "timeUnit" : 1000 } } } } } }
The |
|
Scripting supports parameterized input just like any other script |
This will interpret the script
parameter as an inline
script with the painless
script language and no script parameters. To use a file script use the following syntax:
{ "aggs" : { "load_time_outlier" : { "percentile_ranks" : { "values" : [3, 5], "script" : { "file": "my_script", "params" : { "timeUnit" : 1000 } } } } } }
for indexed scripts replace the file
parameter with an id
parameter.
HDR Histogram
editThis functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.
HDR Histogram (High Dynamic Range Histogram) is an alternative implementation that can be useful when calculating percentile ranks for latency measurements as it can be faster than the t-digest implementation with the trade-off of a larger memory footprint. This implementation maintains a fixed worse-case percentage error (specified as a number of significant digits). This means that if data is recorded with values from 1 microsecond up to 1 hour (3,600,000,000 microseconds) in a histogram set to 3 significant digits, it will maintain a value resolution of 1 microsecond for values up to 1 millisecond and 3.6 seconds (or better) for the maximum tracked value (1 hour).
The HDR Histogram can be used by specifying the method
parameter in the request:
{ "aggs" : { "load_time_outlier" : { "percentile_ranks" : { "field" : "load_time", "values" : [15, 30], "hdr": { "number_of_significant_value_digits" : 3 } } } } }
|
|
|
The HDRHistogram only supports positive values and will error if it is passed a negative value. It is also not a good idea to use the HDRHistogram if the range of values is unknown as this could lead to high memory usage.
Missing value
editThe missing
parameter defines how documents that are missing a value should be treated.
By default they will be ignored but it is also possible to treat them as if they
had a value.