1
0

extended-stats-bucket-aggregation.asciidoc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. .`extended_stats_bucket` Parameters
  18. |===
  19. |Parameter Name |Description |Required |Default Value
  20. |`buckets_path` |The path to the buckets we wish to calculate stats 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. |`sigma` |The number of standard deviations above/below the mean to display |Optional | 2
  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. "stats_monthly_sales": {
  46. "extended_stats_bucket": {
  47. "buckets_paths": "sales_per_month>sales" <1>
  48. }
  49. }
  50. }
  51. }
  52. --------------------------------------------------
  53. <1> `bucket_paths` instructs this `extended_stats_bucket` aggregation that we want the calculate stats for the `sales` aggregation in the
  54. `sales_per_month` date histogram.
  55. And the following may be the response:
  56. [source,js]
  57. --------------------------------------------------
  58. {
  59. "aggregations": {
  60. "sales_per_month": {
  61. "buckets": [
  62. {
  63. "key_as_string": "2015/01/01 00:00:00",
  64. "key": 1420070400000,
  65. "doc_count": 3,
  66. "sales": {
  67. "value": 550
  68. }
  69. },
  70. {
  71. "key_as_string": "2015/02/01 00:00:00",
  72. "key": 1422748800000,
  73. "doc_count": 2,
  74. "sales": {
  75. "value": 60
  76. }
  77. },
  78. {
  79. "key_as_string": "2015/03/01 00:00:00",
  80. "key": 1425168000000,
  81. "doc_count": 2,
  82. "sales": {
  83. "value": 375
  84. }
  85. }
  86. ]
  87. },
  88. "stats_monthly_sales": {
  89. "count": 3,
  90. "min": 60,
  91. "max": 550,
  92. "avg": 328.333333333,
  93. "sum": 985,
  94. "sum_of_squares": 446725,
  95. "variance": 41105.5555556,
  96. "std_deviation": 117.054909559,
  97. "std_deviation_bounds": {
  98. "upper": 562.443152451,
  99. "lower": 94.2235142151
  100. }
  101. }
  102. }
  103. }
  104. --------------------------------------------------