rollup-api.asciidoc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[rollup-api]]
  4. === Rollup API
  5. ++++
  6. <titleabbrev>Rollup</titleabbrev>
  7. ++++
  8. Aggregates an index's time-series data and stores the results in another index.
  9. For example, you can roll up hourly data into daily or weekly summaries.
  10. [source,console]
  11. ----
  12. POST /my-index-000001/_rollup
  13. {
  14. "rollup_index": "my-rollup-index",
  15. "groups": {
  16. "date_histogram": {
  17. "field": "@timestamp",
  18. "calendar_interval": "1d"
  19. },
  20. "terms": {
  21. "fields": [
  22. "my-keyword-field",
  23. "my-other-keyword-field"
  24. ]
  25. }
  26. },
  27. "metrics": [
  28. {
  29. "field": "my-numeric-field",
  30. "metrics": [
  31. "min",
  32. "max",
  33. "avg"
  34. ]
  35. }
  36. ]
  37. }
  38. ----
  39. // TEST[setup:my_index]
  40. [[rollup-api-request]]
  41. ==== {api-request-title}
  42. `PUT /<index>/_rollup`
  43. [[rollup-api-prereqs]]
  44. ==== {api-prereq-title}
  45. If the {es} {security-features} are enabled, you must have the `manage` cluster
  46. privilege to use this API. See <<security-privileges>>.
  47. [[rollup-api-path-params]]
  48. ==== {api-path-parms-title}
  49. `<index>`::
  50. (Required, string)
  51. Index to roll up. Cannot be a <<data-streams,data stream>> or
  52. <<indices-aliases,index alias>>. Does not support <<multi-index,multi-target
  53. syntax>> or wildcards (`*`).
  54. [role="child_attributes"]
  55. [[rollup-api-request-body]]
  56. ==== {api-request-body-title}
  57. `rollup_index`::
  58. (Required, string)
  59. Index that stores the rollup results. Cannot be a <<data-streams,data stream>>
  60. or <<indices-aliases,index alias>>.
  61. +
  62. If this index does not exist, the request creates it. If the `<index>` is a
  63. backing index for a data stream, this new index is a backing index for the same
  64. stream.
  65. `groups`::
  66. (Required, object)
  67. Aggregates and stores fields in the rollup.
  68. +
  69. .Properties of `groups`
  70. [%collapsible%open]
  71. ====
  72. `date_histogram`::
  73. (Required,
  74. <<search-aggregations-bucket-datehistogram-aggregation,`date_histogram`
  75. aggregation>> object)
  76. Groups documents based on a provided time interval.
  77. +
  78. .Properties of `date_histogram`
  79. [%collapsible%open]
  80. =====
  81. `field`::
  82. (Required, string)
  83. <<date,`date`>> or <<date_nanos,`date_nanos`>> field containing a timestamp. If
  84. you're rolling up a backing index or using the {ecs-ref}[Elastic Common Schema
  85. (ECS)], we recommend using `@timestamp`.
  86. `calendar_interval` or `fixed_interval`::
  87. (Required, <<time-units,time units>>)
  88. Time interval used to group documents. For differences between
  89. `calendar_interval` and `fixed_interval`, see <<calendar_and_fixed_intervals>>.
  90. +
  91. TIP: Choose this value carefully. You won't be able to use a smaller interval
  92. later. For example, you can't aggregate daily rollups into hourly
  93. summaries. However, smaller time intervals can greatly increase the size of your
  94. `rollup_index`.
  95. `time_zone`::
  96. (Optional, string)
  97. Time zone for the `field`. Valid values are ISO 8601 UTC offsets, such as
  98. `+01:00` or `-08:00`, and IANA time zone IDs, such as `America/Los_Angeles`.
  99. Defaults to `+00:00` (UTC).
  100. =====
  101. `histogram`::
  102. (Optional, <<search-aggregations-bucket-histogram-aggregation,`histogram`
  103. aggregation>> object)
  104. Groups and stores <<number,numeric>> field values based on a provided interval.
  105. +
  106. .Properties of `histogram`
  107. [%collapsible%open]
  108. =====
  109. `fields`::
  110. (Required*, array of strings)
  111. Array of <<number,numeric>> fields to group. If you specify a `histogram`
  112. object, this property is required.
  113. `interval`::
  114. (Required*, integer)
  115. Numeric interval used to group the `fields`. If you specify a `histogram`
  116. object, this property is required.
  117. =====
  118. `terms`::
  119. (Optional, <<search-aggregations-bucket-terms-aggregation,`terms`
  120. aggregation>> object)
  121. Stores values for <<keyword,keyword family>> and <<number,numeric>> fields.
  122. +
  123. .Properties of `terms`
  124. [%collapsible%open]
  125. =====
  126. `fields`::
  127. (Required*, array of strings)
  128. Array of <<keyword,keyword family>> and <<number,numeric>> fields to store. If
  129. you specify a `terms` object, this property is required.
  130. +
  131. TIP: Avoid storing high-cardinality fields. High-cardinality fields can greatly
  132. increase the size of your `rollup_index`.
  133. =====
  134. ====
  135. `metrics`::
  136. (Optional, array of objects)
  137. Collects and stores metrics for <<number,numeric>> fields.
  138. +
  139. .Properties of `metrics` objects
  140. [%collapsible%open]
  141. ====
  142. `field`::
  143. (Required*, string)
  144. <<number,Numeric>> field to collect metrics for. If you specify a `metrics`
  145. object, this property is required.
  146. `metrics`::
  147. (Required*, array)
  148. Array of metrics to collect. Each value corresponds to a
  149. <<search-aggregations-metrics,metric aggregation>>. Valid values are
  150. <<search-aggregations-metrics-min-aggregation,`min`>>,
  151. <<search-aggregations-metrics-max-aggregation,`max`>>,
  152. <<search-aggregations-metrics-sum-aggregation,`sum`>>,
  153. <<search-aggregations-metrics-avg-aggregation,`avg`>>, and
  154. <<search-aggregations-metrics-valuecount-aggregation,`value_count`>>. You must
  155. specify at least one value. If you specify a `metrics` object, this property is
  156. required.
  157. +
  158. NOTE: The `avg` metric stores both the `sum` and `value_count` values. This lets
  159. you accurately average rollups over larger time intervals. For example, you can
  160. accurately roll up hourly averages into daily averages.
  161. ====
  162. `page_size`::
  163. (Optional, integer)
  164. Maximum number of rollup results to process at once. Defaults to `1000`. Larger
  165. values run faster but require more memory.
  166. +
  167. NOTE: This argument only affects the speed and memory usage of the rollup
  168. operation. It does not affect the rollup results.