extended-stats-bucket-aggregation.asciidoc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. [[search-aggregations-pipeline-extended-stats-bucket-aggregation]]
  2. === Extended stats bucket aggregation
  3. ++++
  4. <titleabbrev>Extended stats bucket</titleabbrev>
  5. ++++
  6. A sibling pipeline aggregation which calculates a variety of stats across all bucket of a specified metric in a sibling aggregation.
  7. The specified metric must be numeric and the sibling aggregation must be a multi-bucket aggregation.
  8. This aggregation provides a few more statistics (sum of squares, standard deviation, etc) compared to the `stats_bucket` aggregation.
  9. ==== Syntax
  10. A `extended_stats_bucket` aggregation looks like this in isolation:
  11. [source,js]
  12. --------------------------------------------------
  13. {
  14. "extended_stats_bucket": {
  15. "buckets_path": "the_sum"
  16. }
  17. }
  18. --------------------------------------------------
  19. // NOTCONSOLE
  20. [[extended-stats-bucket-params]]
  21. .`extended_stats_bucket` Parameters
  22. [options="header"]
  23. |===
  24. |Parameter Name |Description |Required |Default Value
  25. |`buckets_path` |The path to the buckets we wish to calculate stats for (see <<buckets-path-syntax>> for more
  26. details) |Required |
  27. |`gap_policy` |The policy to apply when gaps are found in the data (see <<gap-policy>> for more
  28. details)|Optional | `skip`
  29. |`format` |format to apply to the output value of this aggregation |Optional | `null`
  30. |`sigma` |The number of standard deviations above/below the mean to display |Optional | 2
  31. |===
  32. The following snippet calculates the extended stats for monthly `sales` bucket:
  33. [source,console]
  34. --------------------------------------------------
  35. POST /sales/_search
  36. {
  37. "size": 0,
  38. "aggs": {
  39. "sales_per_month": {
  40. "date_histogram": {
  41. "field": "date",
  42. "calendar_interval": "month"
  43. },
  44. "aggs": {
  45. "sales": {
  46. "sum": {
  47. "field": "price"
  48. }
  49. }
  50. }
  51. },
  52. "stats_monthly_sales": {
  53. "extended_stats_bucket": {
  54. "buckets_path": "sales_per_month>sales" <1>
  55. }
  56. }
  57. }
  58. }
  59. --------------------------------------------------
  60. // TEST[setup:sales]
  61. <1> `bucket_paths` instructs this `extended_stats_bucket` aggregation that we want the calculate stats for the `sales` aggregation in the
  62. `sales_per_month` date histogram.
  63. And the following may be the response:
  64. [source,console-result]
  65. --------------------------------------------------
  66. {
  67. "took": 11,
  68. "timed_out": false,
  69. "_shards": ...,
  70. "hits": ...,
  71. "aggregations": {
  72. "sales_per_month": {
  73. "buckets": [
  74. {
  75. "key_as_string": "2015/01/01 00:00:00",
  76. "key": 1420070400000,
  77. "doc_count": 3,
  78. "sales": {
  79. "value": 550.0
  80. }
  81. },
  82. {
  83. "key_as_string": "2015/02/01 00:00:00",
  84. "key": 1422748800000,
  85. "doc_count": 2,
  86. "sales": {
  87. "value": 60.0
  88. }
  89. },
  90. {
  91. "key_as_string": "2015/03/01 00:00:00",
  92. "key": 1425168000000,
  93. "doc_count": 2,
  94. "sales": {
  95. "value": 375.0
  96. }
  97. }
  98. ]
  99. },
  100. "stats_monthly_sales": {
  101. "count": 3,
  102. "min": 60.0,
  103. "max": 550.0,
  104. "avg": 328.3333333333333,
  105. "sum": 985.0,
  106. "sum_of_squares": 446725.0,
  107. "variance": 41105.55555555556,
  108. "variance_population": 41105.55555555556,
  109. "variance_sampling": 61658.33333333334,
  110. "std_deviation": 202.74505063146563,
  111. "std_deviation_population": 202.74505063146563,
  112. "std_deviation_sampling": 248.3109609609156,
  113. "std_deviation_bounds": {
  114. "upper": 733.8234345962646,
  115. "lower": -77.15676792959795,
  116. "upper_population" : 733.8234345962646,
  117. "lower_population" : -77.15676792959795,
  118. "upper_sampling" : 824.9552552551645,
  119. "lower_sampling" : -168.28858858849787
  120. }
  121. }
  122. }
  123. }
  124. --------------------------------------------------
  125. // TESTRESPONSE[s/"took": 11/"took": $body.took/]
  126. // TESTRESPONSE[s/"_shards": \.\.\./"_shards": $body._shards/]
  127. // TESTRESPONSE[s/"hits": \.\.\./"hits": $body.hits/]