extended-stats-bucket-aggregation.asciidoc 4.2 KB

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