rollup-api.asciidoc 5.3 KB

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