extended-stats-bucket-aggregation.asciidoc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. [[search-aggregations-pipeline-extended-stats-bucket-aggregation]]
  2. === Extended Stats Bucket Aggregation
  3. coming[2.1.0]
  4. experimental[]
  5. A sibling pipeline aggregation which calculates a variety of stats 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. This aggregation provides a few more statistics (sum of squares, standard deviation, etc) compared to the `stats_bucket` aggregation.
  8. ==== Syntax
  9. A `extended_stats_bucket` aggregation looks like this in isolation:
  10. [source,js]
  11. --------------------------------------------------
  12. {
  13. "extended_stats_bucket": {
  14. "buckets_path": "the_sum"
  15. }
  16. }
  17. --------------------------------------------------
  18. .`extended_stats_bucket` Parameters
  19. |===
  20. |Parameter Name |Description |Required |Default Value
  21. |`buckets_path` |The path to the buckets we wish to calculate stats for (see <<buckets-path-syntax>> for more
  22. details) |Required |
  23. |`gap_policy` |The policy to apply when gaps are found in the data (see <<gap-policy>> for more
  24. details)|Optional | `skip`
  25. |`format` |format to apply to the output value of this aggregation |Optional | `null`
  26. |`sigma` |The number of standard deviations above/below the mean to display |Optional | 2
  27. |===
  28. The following snippet calculates the sum of all the total monthly `sales` buckets:
  29. [source,js]
  30. --------------------------------------------------
  31. {
  32. "aggs" : {
  33. "sales_per_month" : {
  34. "date_histogram" : {
  35. "field" : "date",
  36. "interval" : "month"
  37. },
  38. "aggs": {
  39. "sales": {
  40. "sum": {
  41. "field": "price"
  42. }
  43. }
  44. }
  45. },
  46. "stats_monthly_sales": {
  47. "extended_stats_bucket": {
  48. "buckets_paths": "sales_per_month>sales" <1>
  49. }
  50. }
  51. }
  52. }
  53. --------------------------------------------------
  54. <1> `bucket_paths` instructs this `extended_stats_bucket` aggregation that we want the calculate stats for the `sales` aggregation in the
  55. `sales_per_month` date histogram.
  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. "stats_monthly_sales": {
  90. "count": 3,
  91. "min": 60,
  92. "max": 550,
  93. "avg": 328.333333333,
  94. "sum": 985,
  95. "sum_of_squares": 446725,
  96. "variance": 41105.5555556,
  97. "std_deviation": 117.054909559,
  98. "std_deviation_bounds": {
  99. "upper": 562.443152451,
  100. "lower": 94.2235142151
  101. }
  102. }
  103. }
  104. }
  105. --------------------------------------------------