percentile-rank-aggregation.asciidoc 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. [[search-aggregations-metrics-percentile-rank-aggregation]]
  2. === Percentile Ranks Aggregation
  3. A `multi-value` metrics aggregation that calculates one or more percentile ranks
  4. over numeric values extracted from the aggregated documents. These values
  5. can be extracted either from specific numeric fields in the documents, or
  6. be generated by a provided script.
  7. [NOTE]
  8. ==================================================
  9. Please see <<search-aggregations-metrics-percentile-aggregation-approximation>>
  10. and <<search-aggregations-metrics-percentile-aggregation-compression>> for advice
  11. regarding approximation and memory use of the percentile ranks aggregation
  12. ==================================================
  13. Percentile rank show the percentage of observed values which are below certain
  14. value. For example, if a value is greater than or equal to 95% of the observed values
  15. it is said to be at the 95th percentile rank.
  16. Assume your data consists of website load times. You may have a service agreement that
  17. 95% of page loads completely within 15ms and 99% of page loads complete within 30ms.
  18. Let's look at a range of percentiles representing load time:
  19. [source,js]
  20. --------------------------------------------------
  21. {
  22. "aggs" : {
  23. "load_time_outlier" : {
  24. "percentile_ranks" : {
  25. "field" : "load_time", <1>
  26. "values" : [15, 30]
  27. }
  28. }
  29. }
  30. }
  31. --------------------------------------------------
  32. <1> The field `load_time` must be a numeric field
  33. The response will look like this:
  34. [source,js]
  35. --------------------------------------------------
  36. {
  37. ...
  38. "aggregations": {
  39. "load_time_outlier": {
  40. "values" : {
  41. "15": 92,
  42. "30": 100
  43. }
  44. }
  45. }
  46. }
  47. --------------------------------------------------
  48. From this information you can determine you are hitting the 99% load time target but not quite
  49. hitting the 95% load time target
  50. ==== Script
  51. The percentile rank metric supports scripting. For example, if our load times
  52. are in milliseconds but we want to specify values in seconds, we could use
  53. a script to convert them on-the-fly:
  54. [source,js]
  55. --------------------------------------------------
  56. {
  57. "aggs" : {
  58. "load_time_outlier" : {
  59. "percentile_ranks" : {
  60. "values" : [3, 5],
  61. "script" : "doc['load_time'].value / timeUnit", <1>
  62. "params" : {
  63. "timeUnit" : 1000 <2>
  64. }
  65. }
  66. }
  67. }
  68. }
  69. --------------------------------------------------
  70. <1> The `field` parameter is replaced with a `script` parameter, which uses the
  71. script to generate values which percentile ranks are calculated on
  72. <2> Scripting supports parameterized input just like any other script
  73. TIP: The `script` parameter expects an inline script. Use `script_id` for indexed scripts and `script_file` for scripts in the `config/scripts/` directory.