percentiles-bucket-aggregation.asciidoc 3.8 KB

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