percentiles-bucket-aggregation.asciidoc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. [[search-aggregations-pipeline-percentiles-bucket-aggregation]]
  2. === Percentiles Bucket Aggregation
  3. experimental[]
  4. A sibling pipeline aggregation which calculates percentiles across all bucket of a specified metric in a sibling aggregation.
  5. The specified metric must be numeric and the sibling aggregation must be a multi-bucket aggregation.
  6. ==== Syntax
  7. A `percentiles_bucket` aggregation looks like this in isolation:
  8. [source,js]
  9. --------------------------------------------------
  10. {
  11. "percentiles_bucket": {
  12. "buckets_path": "the_sum"
  13. }
  14. }
  15. --------------------------------------------------
  16. .`sum_bucket` Parameters
  17. |===
  18. |Parameter Name |Description |Required |Default Value
  19. |`buckets_path` |The path to the buckets we wish to find the sum for (see <<buckets-path-syntax>> for more
  20. details) |Required |
  21. |`gap_policy` |The policy to apply when gaps are found in the data (see <<gap-policy>> for more
  22. details)|Optional | `skip`
  23. |`format` |format to apply to the output value of this aggregation |Optional | `null`
  24. |`percents` |The list of percentiles to calculate |Optional | `[ 1, 5, 25, 50, 75, 95, 99 ]`
  25. |===
  26. The following snippet calculates the sum of all the total monthly `sales` buckets:
  27. [source,js]
  28. --------------------------------------------------
  29. {
  30. "aggs" : {
  31. "sales_per_month" : {
  32. "date_histogram" : {
  33. "field" : "date",
  34. "interval" : "month"
  35. },
  36. "aggs": {
  37. "sales": {
  38. "sum": {
  39. "field": "price"
  40. }
  41. }
  42. }
  43. },
  44. "sum_monthly_sales": {
  45. "percentiles_bucket": {
  46. "buckets_paths": "sales_per_month>sales", <1>
  47. "percents": [ 25.0, 50.0, 75.0 ] <2>
  48. }
  49. }
  50. }
  51. }
  52. --------------------------------------------------
  53. <1> `bucket_paths` instructs this percentiles_bucket aggregation that we want to calculate percentiles for
  54. the `sales` aggregation in the `sales_per_month` date histogram.
  55. <2> `percents` specifies which percentiles we wish to calculate, in this case, the 25th, 50th and 75th percentil
  56. And the following may be the response:
  57. [source,js]
  58. --------------------------------------------------
  59. {
  60. "aggregations": {
  61. "sales_per_month": {
  62. "buckets": [
  63. {
  64. "key_as_string": "2015/01/01 00:00:00",
  65. "key": 1420070400000,
  66. "doc_count": 3,
  67. "sales": {
  68. "value": 550
  69. }
  70. },
  71. {
  72. "key_as_string": "2015/02/01 00:00:00",
  73. "key": 1422748800000,
  74. "doc_count": 2,
  75. "sales": {
  76. "value": 60
  77. }
  78. },
  79. {
  80. "key_as_string": "2015/03/01 00:00:00",
  81. "key": 1425168000000,
  82. "doc_count": 2,
  83. "sales": {
  84. "value": 375
  85. }
  86. }
  87. ]
  88. },
  89. "percentiles_monthly_sales": {
  90. "values" : {
  91. "25.0": 60,
  92. "50.0": 375",
  93. "75.0": 550
  94. }
  95. }
  96. }
  97. }
  98. --------------------------------------------------
  99. ==== Percentiles_bucket implementation
  100. The Percentile Bucket returns the nearest input data point that is not greater than the requested percentile; it does not
  101. interpolate between data points.
  102. The percentiles are calculated exactly and is not an approximation (unlike the Percentiles Metric). This means
  103. the implementation maintains an in-memory, sorted list of your data to compute the percentiles, before discarding the
  104. data. You may run into memory pressure issues if you attempt to calculate percentiles over many millions of
  105. data-points in a single `percentiles_bucket`.