rollup-api.asciidoc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. [[rollup-api-request]]
  40. ==== {api-request-title}
  41. `PUT /<index>/_rollup/<rollup-index>`
  42. [[rollup-api-prereqs]]
  43. ==== {api-prereq-title}
  44. If the {es} {security-features} are enabled, you must have the `manage` or
  45. `manage_rollup` cluster privilege to use this API. See <<security-privileges>>.
  46. [[rollup-api-path-params]]
  47. ==== {api-path-parms-title}
  48. `<index>`::
  49. (Required, string)
  50. Index to roll up. Cannot be a <<data-streams,data stream>> or
  51. <<indices-aliases,index alias>>. Does not support <<multi-index,multi-target
  52. syntax>> or wildcards (`*`).
  53. `<rollup-index>`::
  54. (Required, string)
  55. New index that stores the rollup results. Cannot be an existing index,
  56. a <<data-streams,data stream>>, or an <<indices-aliases,index alias>>.
  57. +
  58. The request creates this index with
  59. <<index-modules-blocks,`index.blocks.write`>> set to `true`. If the source
  60. `<index>` is a backing index for a data stream, this index is a backing index
  61. for the same stream.
  62. [role="child_attributes"]
  63. [[rollup-api-request-body]]
  64. ==== {api-request-body-title}
  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 the
  94. resulting 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 the resulting 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 of strings)
  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 rollup index stores these metrics in an
  159. <<aggregate-metric-double,`aggregate_metric_double`>> field. The `avg` metric
  160. stores both the `sum` and `value_count` values. This lets you accurately average
  161. rollups over larger time intervals. For example, you can accurately roll up
  162. hourly averages into daily averages.
  163. =====
  164. `page_size`::
  165. (Optional, integer)
  166. Maximum number of rollup results to process at once. Defaults to `1000`. Larger
  167. values run faster but require more memory.
  168. +
  169. NOTE: This argument only affects the speed and memory usage of the rollup
  170. operation. It does not affect the rollup results.
  171. `timeout`::
  172. (Optional, <<time-units,time value>>)
  173. Time to wait for the request to complete. Defaults to `20s` (20 seconds).