extended-stats-bucket-aggregation.asciidoc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. [[search-aggregations-pipeline-extended-stats-bucket-aggregation]]
  2. === Extended Stats Bucket Aggregation
  3. experimental[]
  4. A sibling pipeline aggregation which calculates a variety of stats 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. This aggregation provides a few more statistics (sum of squares, standard deviation, etc) compared to the `stats_bucket` aggregation.
  7. ==== Syntax
  8. A `extended_stats_bucket` aggregation looks like this in isolation:
  9. [source,js]
  10. --------------------------------------------------
  11. {
  12. "extended_stats_bucket": {
  13. "buckets_path": "the_sum"
  14. }
  15. }
  16. --------------------------------------------------
  17. // NOTCONSOLE
  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. POST /sales/_search
  32. {
  33. "size": 0,
  34. "aggs" : {
  35. "sales_per_month" : {
  36. "date_histogram" : {
  37. "field" : "date",
  38. "interval" : "month"
  39. },
  40. "aggs": {
  41. "sales": {
  42. "sum": {
  43. "field": "price"
  44. }
  45. }
  46. }
  47. },
  48. "stats_monthly_sales": {
  49. "extended_stats_bucket": {
  50. "buckets_path": "sales_per_month>sales" <1>
  51. }
  52. }
  53. }
  54. }
  55. --------------------------------------------------
  56. // CONSOLE
  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,js]
  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. "std_deviation": 202.74505063146563,
  106. "std_deviation_bounds": {
  107. "upper": 733.8234345962646,
  108. "lower": -77.15676792959795
  109. }
  110. }
  111. }
  112. }
  113. --------------------------------------------------
  114. // TESTRESPONSE[s/"took": 11/"took": $body.took/]
  115. // TESTRESPONSE[s/"_shards": \.\.\./"_shards": $body._shards/]
  116. // TESTRESPONSE[s/"hits": \.\.\./"hits": $body.hits/]