rollup-api.asciidoc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 a new read-only
  9. index. For example, you can roll up hourly data into daily or weekly summaries.
  10. [source,console]
  11. ----
  12. POST /my-index-000001/_rollup/rollup-my-index-000001
  13. {
  14. "groups": {
  15. "date_histogram": {
  16. "field": "@timestamp",
  17. "calendar_interval": "1d"
  18. },
  19. "terms": {
  20. "fields": [
  21. "my-keyword-field",
  22. "my-other-keyword-field"
  23. ]
  24. }
  25. },
  26. "metrics": [
  27. {
  28. "field": "my-numeric-field",
  29. "metrics": [
  30. "min",
  31. "max",
  32. "avg"
  33. ]
  34. }
  35. ]
  36. }
  37. ----
  38. // TEST[setup:my_index]
  39. // TEST[s/my-keyword-field/http.request.method/]
  40. // TEST[s/my-other-keyword-field/user.id/]
  41. // TEST[s/my-numeric-field/http.response.bytes/]
  42. [[rollup-api-request]]
  43. ==== {api-request-title}
  44. `PUT /<index>/_rollup/<rollup-index>`
  45. [[rollup-api-prereqs]]
  46. ==== {api-prereq-title}
  47. * You can only roll up an index that contains:
  48. ** A <<date,`date`>> or <<date_nanos,`date_nanos`>> timestamp field.
  49. ** At least one metric to roll up. This field must be a <<number,numeric>>,
  50. `date`, or `date_nanos` field other than the timestamp field. This field
  51. cannot be an `unsigned_long`.
  52. * If the {es} {security-features} are enabled, you must have the `manage`
  53. <<privileges-list-indices,index privilege>> for the index you roll up.
  54. [[rollup-api-path-params]]
  55. ==== {api-path-parms-title}
  56. `<index>`::
  57. (Required, string)
  58. Index to roll up. Cannot be a <<data-streams,data stream>> or
  59. <<indices-aliases,index alias>>. Does not support <<multi-index,multi-target
  60. syntax>> or wildcards (`*`).
  61. `<rollup-index>`::
  62. (Required, string)
  63. New index that stores the rollup results. Cannot be an existing index,
  64. a <<data-streams,data stream>>, or an <<indices-aliases,index alias>>.
  65. +
  66. The request creates this index with
  67. <<index-modules-blocks,`index.blocks.write`>> set to `true`. If the source
  68. `<index>` is a backing index for a data stream, this index is a backing index
  69. for the same stream.
  70. [role="child_attributes"]
  71. [[rollup-api-request-body]]
  72. ==== {api-request-body-title}
  73. // tag::rollup-config[]
  74. `groups`::
  75. (Required, object)
  76. Aggregates and groups documents in the rollup.
  77. +
  78. .Properties of `groups`
  79. [%collapsible%open]
  80. =====
  81. `date_histogram`::
  82. (Required,
  83. <<search-aggregations-bucket-datehistogram-aggregation,`date_histogram`
  84. aggregation>> object)
  85. Groups documents based on a provided time interval.
  86. +
  87. .Properties of `date_histogram`
  88. [%collapsible%open]
  89. ======
  90. `field`::
  91. (Required, string)
  92. <<date,`date`>> or <<date_nanos,`date_nanos`>> field containing a timestamp. If
  93. you're rolling up a backing index or using the {ecs-ref}[Elastic Common Schema
  94. (ECS)], we recommend using `@timestamp`.
  95. +
  96. WARNING: Do not use this field in `metrics`. If you do, the rollup attempt will
  97. fail.
  98. `calendar_interval` or `fixed_interval`::
  99. (Required, <<time-units,time units>>)
  100. Time interval used to group documents. For differences between
  101. `calendar_interval` and `fixed_interval`, see <<calendar_and_fixed_intervals>>.
  102. +
  103. TIP: Choose this value carefully. You won't be able to use a smaller interval
  104. later. For example, you can't aggregate daily rollups into hourly
  105. summaries. However, smaller time intervals can greatly increase the size of the
  106. resulting rollup index.
  107. `time_zone`::
  108. (Optional, string)
  109. Time zone for the `field`. Valid values are ISO 8601 UTC offsets, such as
  110. `+01:00` or `-08:00`, and IANA time zone IDs, such as `America/Los_Angeles`.
  111. Defaults to `+00:00` (UTC).
  112. ======
  113. `histogram`::
  114. (Optional, <<search-aggregations-bucket-histogram-aggregation,`histogram`
  115. aggregation>> object)
  116. Groups documents based on a numeric interval.
  117. +
  118. .Properties of `histogram`
  119. [%collapsible%open]
  120. ======
  121. `fields`::
  122. (Required*, string or array of strings)
  123. <<number,Numeric>> fields to group. `unsigned_long` fields are not supported. If
  124. you specify a `histogram` object, this property is required.
  125. +
  126. WARNING: Do not use these fields in `metrics`. If you do, the rollup attempt
  127. will fail.
  128. `interval`::
  129. (Required*, integer)
  130. Numeric interval used to group the `fields`. If you specify a `histogram`
  131. object, this property is required.
  132. ======
  133. `terms`::
  134. (Optional, <<search-aggregations-bucket-terms-aggregation,`terms`
  135. aggregation>> object)
  136. Groups documents based on unique field values.
  137. +
  138. .Properties of `terms`
  139. [%collapsible%open]
  140. ======
  141. `fields`::
  142. +
  143. --
  144. (Required*, string or array of strings)
  145. Fields to store unique values for. Supports the following field types:
  146. * <<keyword,Keyword family>> types
  147. * <<number,Numeric>> types, excluding `unsigned_long`
  148. * <<text,`text`>> fields with <<fielddata-mapping-param,`fielddata`>> enabled
  149. If you specify a `terms` object, this property is required.
  150. TIP: Avoid storing high-cardinality fields. High-cardinality fields can greatly
  151. increase the size of the resulting rollup index.
  152. --
  153. ======
  154. =====
  155. `metrics`::
  156. (Required, object or array of objects)
  157. Collects and stores metrics for fields. You must specify at least one `metrics`
  158. object.
  159. +
  160. .Properties of `metrics` objects
  161. [%collapsible%open]
  162. =====
  163. `field`::
  164. (Required, string)
  165. <<number,Numeric>>, <<date,`date`>>, or <<date_nanos,`date_nanos`>> field to
  166. collect metrics for. `unsigned_long` fields are not supported.
  167. +
  168. WARNING: Do not use fields specified in `histogram` or `date_histogram`. If you
  169. do, the rollup attempt will fail.
  170. `metrics`::
  171. (Required, string or array of strings)
  172. Metrics to collect. Each value corresponds to a
  173. <<search-aggregations-metrics,metric aggregation>>. Valid values are
  174. <<search-aggregations-metrics-min-aggregation,`min`>>,
  175. <<search-aggregations-metrics-max-aggregation,`max`>>,
  176. <<search-aggregations-metrics-sum-aggregation,`sum`>>,
  177. <<search-aggregations-metrics-avg-aggregation,`avg`>>, and
  178. <<search-aggregations-metrics-valuecount-aggregation,`value_count`>>. <<date,`date`>> and <<date_nanos,`date_nanos`>>
  179. fields only support the `max`, `min`, and `value_count` metrics. You must specify
  180. at least one value.
  181. +
  182. NOTE: The rollup index stores these metrics in an
  183. <<aggregate-metric-double,`aggregate_metric_double`>> field. The `avg` metric
  184. stores both the `sum` and `value_count` values. This lets you accurately average
  185. rollups over larger time intervals. For example, you can accurately roll up
  186. hourly averages into daily averages.
  187. =====
  188. // end::rollup-config[]
  189. `page_size`::
  190. (Optional, integer)
  191. Maximum number of rollup results to process at once. Defaults to `1000`. Larger
  192. values run faster but require more memory.
  193. +
  194. NOTE: This argument only affects the speed and memory usage of the rollup
  195. operation. It does not affect the rollup results.
  196. `timeout`::
  197. (Optional, <<time-units,time value>>)
  198. Time to wait for the request to complete. Defaults to `20s` (20 seconds).