min-bucket-aggregation.asciidoc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. [[search-aggregations-reducer-min-bucket-aggregation]]
  2. === Min Bucket Aggregation
  3. A sibling reducer aggregation which identifies the bucket(s) with the minimum value of a specified metric in a sibling aggregation
  4. and outputs both the value and the key(s) of the bucket(s). The specified metric must be numeric and the sibling aggregation must
  5. be a multi-bucket aggregation.
  6. ==== Syntax
  7. A `max_bucket` aggregation looks like this in isolation:
  8. [source,js]
  9. --------------------------------------------------
  10. {
  11. "min_bucket": {
  12. "buckets_path": "the_sum"
  13. }
  14. }
  15. --------------------------------------------------
  16. .`min_bucket` Parameters
  17. |===
  18. |Parameter Name |Description |Required |Default Value
  19. |`buckets_path` |Path to the metric of interest (see <<bucket-path-syntax, `buckets_path` Syntax>> for more details |Required |
  20. |===
  21. The following snippet calculates the minimum of the total monthly `sales`:
  22. [source,js]
  23. --------------------------------------------------
  24. {
  25. "aggs" : {
  26. "sales_per_month" : {
  27. "date_histogram" : {
  28. "field" : "date",
  29. "interval" : "month"
  30. },
  31. "aggs": {
  32. "sales": {
  33. "sum": {
  34. "field": "price"
  35. }
  36. }
  37. }
  38. },
  39. "min_monthly_sales": {
  40. "min_bucket": {
  41. "buckets_paths": "sales_per_month>sales" <1>
  42. }
  43. }
  44. }
  45. }
  46. --------------------------------------------------
  47. <1> `bucket_paths` instructs this max_bucket aggregation that we want the minimum value of the `sales` aggregation in the
  48. `sales_per_month` date histogram.
  49. And the following may be the response:
  50. [source,js]
  51. --------------------------------------------------
  52. {
  53. "aggregations": {
  54. "sales_per_month": {
  55. "buckets": [
  56. {
  57. "key_as_string": "2015/01/01 00:00:00",
  58. "key": 1420070400000,
  59. "doc_count": 3,
  60. "sales": {
  61. "value": 550
  62. }
  63. },
  64. {
  65. "key_as_string": "2015/02/01 00:00:00",
  66. "key": 1422748800000,
  67. "doc_count": 2,
  68. "sales": {
  69. "value": 60
  70. }
  71. },
  72. {
  73. "key_as_string": "2015/03/01 00:00:00",
  74. "key": 1425168000000,
  75. "doc_count": 2,
  76. "sales": {
  77. "value": 375
  78. }
  79. }
  80. ]
  81. },
  82. "min_monthly_sales": {
  83. "keys": ["2015/02/01 00:00:00"], <1>
  84. "value": 60
  85. }
  86. }
  87. }
  88. --------------------------------------------------
  89. <1> `keys` is an array of strings since the minimum value may be present in multiple buckets