put-job.asciidoc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. [role="xpack"]
  2. [[rollup-put-job]]
  3. === Create {rollup-jobs} API
  4. [subs="attributes"]
  5. ++++
  6. <titleabbrev>Create {rollup-jobs}</titleabbrev>
  7. ++++
  8. Creates a {rollup-job}.
  9. experimental[]
  10. NOTE: For version 8.5 and above we recommend <<downsampling,downsampling>> over
  11. rollups as a way to reduce your storage costs for time series data.
  12. [[rollup-put-job-api-request]]
  13. ==== {api-request-title}
  14. `PUT _rollup/job/<job_id>`
  15. [[rollup-put-job-api-prereqs]]
  16. ==== {api-prereq-title}
  17. * If the {es} {security-features} are enabled, you must have `manage` or
  18. `manage_rollup` cluster privileges to use this API. For more information, see
  19. <<security-privileges>>.
  20. [[rollup-put-job-api-desc]]
  21. ==== {api-description-title}
  22. The {rollup-job} configuration contains all the details about how the job should
  23. run, when it indexes documents, and what future queries will be able to execute
  24. against the rollup index.
  25. There are three main sections to the job configuration: the logistical details
  26. about the job (cron schedule, etc), the fields that are used for grouping, and
  27. what metrics to collect for each group.
  28. Jobs are created in a `STOPPED` state. You can start them with the
  29. <<rollup-start-job,start {rollup-jobs} API>>.
  30. [[rollup-put-job-api-path-params]]
  31. ==== {api-path-parms-title}
  32. `<job_id>`::
  33. (Required, string) Identifier for the {rollup-job}. This can be any
  34. alphanumeric string and uniquely identifies the data that is associated with
  35. the {rollup-job}. The ID is persistent; it is stored with the rolled up data.
  36. If you create a job, let it run for a while, then delete the job, the data
  37. that the job rolled up is still be associated with this job ID. You cannot
  38. create a new job with the same ID since that could lead to problems with
  39. mismatched job configurations.
  40. [role="child_attributes"]
  41. [[rollup-put-job-api-request-body]]
  42. ==== {api-request-body-title}
  43. `cron`::
  44. (Required, string) A cron string which defines the intervals when the
  45. {rollup-job} should be executed. When the interval triggers, the indexer
  46. attempts to rollup the data in the index pattern. The cron pattern is
  47. unrelated to the time interval of the data being rolled up. For example, you
  48. may wish to create hourly rollups of your document but to only run the indexer
  49. on a daily basis at midnight, as defined by the cron. The cron pattern is
  50. defined just like a {watcher} cron schedule.
  51. //Begin groups
  52. [[rollup-groups-config]]
  53. `groups`::
  54. (Required, object) Defines the grouping fields and aggregations that are
  55. defined for this {rollup-job}. These fields will then be available later for
  56. aggregating into buckets.
  57. +
  58. These aggs and fields can be used in any combination. Think of the `groups`
  59. configuration as defining a set of tools that can later be used in aggregations
  60. to partition the data. Unlike raw data, we have to think ahead to which fields
  61. and aggregations might be used. Rollups provide enough flexibility that you
  62. simply need to determine _which_ fields are needed, not _in what order_ they are
  63. needed.
  64. +
  65. There are three types of groupings currently available: `date_histogram`,
  66. `histogram`, and `terms`.
  67. +
  68. .Properties of `groups`
  69. [%collapsible%open]
  70. ====
  71. //Begin date_histogram
  72. `date_histogram`:::
  73. (Required, object) A date histogram group aggregates a `date` field into
  74. time-based buckets. This group is *mandatory*; you currently cannot rollup
  75. documents without a timestamp and a `date_histogram` group. The
  76. `date_histogram` group has several parameters:
  77. +
  78. .Properties of `date_histogram`
  79. [%collapsible%open]
  80. =====
  81. `calendar_interval` or `fixed_interval`::::
  82. (Required, <<time-units,time units>>) The interval of time buckets to be
  83. generated when rolling up. For example, `60m` produces 60 minute (hourly)
  84. rollups. This follows standard time formatting syntax as used elsewhere in {es}.
  85. The interval defines the _minimum_ interval that can be aggregated only. If
  86. hourly (`60m`) intervals are configured, <<rollup-search,rollup search>>
  87. can execute aggregations with 60m or greater (weekly, monthly, etc) intervals.
  88. So define the interval as the smallest unit that you wish to later query. For
  89. more information about the difference between calendar and fixed time
  90. intervals, see <<calendar_and_fixed_intervals>>.
  91. +
  92. --
  93. NOTE: Smaller, more granular intervals take up proportionally more space.
  94. --
  95. `delay`::::
  96. (Optional,<<time-units,time units>>) How long to wait before rolling up new
  97. documents. By default, the indexer attempts to roll up all data that is
  98. available. However, it is not uncommon for data to arrive out of order,
  99. sometimes even a few days late. The indexer is unable to deal with data that
  100. arrives after a time-span has been rolled up. That is to say, there is no
  101. provision to update already-existing rollups.
  102. +
  103. --
  104. Instead, you should specify a `delay` that matches the longest period of time
  105. you expect out-of-order data to arrive. For example, a `delay` of `1d`
  106. instructs the indexer to roll up documents up to `now - 1d`, which provides
  107. a day of buffer time for out-of-order documents to arrive.
  108. --
  109. `field`::::
  110. (Required, string) The date field that is to be rolled up.
  111. `time_zone`::::
  112. (Optional, string) Defines what time_zone the rollup documents are stored as.
  113. Unlike raw data, which can shift timezones on the fly, rolled documents have to
  114. be stored with a specific timezone. By default, rollup documents are stored
  115. in `UTC`.
  116. =====
  117. //End date_histogram
  118. //Begin histogram
  119. `histogram`:::
  120. (Optional, object) The histogram group aggregates one or more numeric fields
  121. into numeric histogram intervals.
  122. +
  123. .Properties of `histogram`
  124. [%collapsible%open]
  125. =====
  126. `fields`::::
  127. (Required, array) The set of fields that you wish to build histograms for. All
  128. fields specified must be some kind of numeric. Order does not matter.
  129. `interval`::::
  130. (Required, integer) The interval of histogram buckets to be generated when
  131. rolling up. For example, a value of `5` creates buckets that are five units wide
  132. (`0-5`, `5-10`, etc). Note that only one interval can be specified in the
  133. `histogram` group, meaning that all fields being grouped via the histogram
  134. must share the same interval.
  135. =====
  136. //End histogram
  137. //Begin terms
  138. `terms`:::
  139. (Optional, object) The terms group can be used on `keyword` or numeric fields to
  140. allow bucketing via the `terms` aggregation at a later point. The indexer
  141. enumerates and stores _all_ values of a field for each time-period. This can be
  142. potentially costly for high-cardinality groups such as IP addresses, especially
  143. if the time-bucket is particularly sparse.
  144. +
  145. --
  146. TIP: While it is unlikely that a rollup will ever be larger in size than the raw
  147. data, defining `terms` groups on multiple high-cardinality fields can
  148. effectively reduce the compression of a rollup to a large extent. You should be
  149. judicious which high-cardinality fields are included for that reason.
  150. --
  151. +
  152. .Properties of `terms`
  153. [%collapsible%open]
  154. =====
  155. `fields`::::
  156. (Required, string) The set of fields that you wish to collect terms for. This
  157. array can contain fields that are both `keyword` and numerics. Order does not
  158. matter.
  159. =====
  160. //End terms
  161. ====
  162. //End groups
  163. `index_pattern`::
  164. (Required, string) The index or index pattern to roll up. Supports
  165. wildcard-style patterns (`logstash-*`). The job attempts to rollup the entire
  166. index or index-pattern.
  167. +
  168. --
  169. NOTE: The `index_pattern` cannot be a pattern that would also match the
  170. destination `rollup_index`. For example, the pattern `foo-*` would match the
  171. rollup index `foo-rollup`. This situation would cause problems because the
  172. {rollup-job} would attempt to rollup its own data at runtime. If you attempt to
  173. configure a pattern that matches the `rollup_index`, an exception occurs to
  174. prevent this behavior.
  175. --
  176. //Begin metrics
  177. [[rollup-metrics-config]]
  178. `metrics`::
  179. (Optional, object) Defines the metrics to collect for each grouping tuple. By
  180. default, only the doc_counts are collected for each group. To make rollup useful,
  181. you will often add metrics like averages, mins, maxes, etc. Metrics are defined
  182. on a per-field basis and for each field you configure which metric should be
  183. collected.
  184. +
  185. The `metrics` configuration accepts an array of objects, where each object has
  186. two parameters.
  187. +
  188. .Properties of metric objects
  189. [%collapsible%open]
  190. ====
  191. `field`:::
  192. (Required, string) The field to collect metrics for. This must be a numeric of
  193. some kind.
  194. `metrics`:::
  195. (Required, array) An array of metrics to collect for the field. At least one
  196. metric must be configured. Acceptable metrics are `min`,`max`,`sum`,`avg`, and
  197. `value_count`.
  198. ====
  199. //End metrics
  200. `page_size`::
  201. (Required, integer) The number of bucket results that are processed on each
  202. iteration of the rollup indexer. A larger value tends to execute faster, but
  203. requires more memory during processing. This value has no effect on how the data
  204. is rolled up; it is merely used for tweaking the speed or memory cost of
  205. the indexer.
  206. `rollup_index`::
  207. (Required, string) The index that contains the rollup results. The index can
  208. be shared with other {rollup-jobs}. The data is stored so that it doesn't
  209. interfere with unrelated jobs.
  210. `timeout`::
  211. (Optional, <<time-units,time value>>)
  212. Time to wait for the request to complete. Defaults to `20s` (20 seconds).
  213. [[rollup-put-job-api-example]]
  214. ==== {api-example-title}
  215. The following example creates a {rollup-job} named `sensor`, targeting the
  216. `sensor-*` index pattern:
  217. [source,console]
  218. --------------------------------------------------
  219. PUT _rollup/job/sensor
  220. {
  221. "index_pattern": "sensor-*",
  222. "rollup_index": "sensor_rollup",
  223. "cron": "*/30 * * * * ?",
  224. "page_size": 1000,
  225. "groups": { <1>
  226. "date_histogram": {
  227. "field": "timestamp",
  228. "fixed_interval": "1h",
  229. "delay": "7d"
  230. },
  231. "terms": {
  232. "fields": [ "node" ]
  233. }
  234. },
  235. "metrics": [ <2>
  236. {
  237. "field": "temperature",
  238. "metrics": [ "min", "max", "sum" ]
  239. },
  240. {
  241. "field": "voltage",
  242. "metrics": [ "avg" ]
  243. }
  244. ]
  245. }
  246. --------------------------------------------------
  247. // TEST[setup:sensor_index]
  248. <1> This configuration enables date histograms to be used on the `timestamp`
  249. field and `terms` aggregations to be used on the `node` field.
  250. <2> This configuration defines metrics over two fields: `temperature` and
  251. `voltage`. For the `temperature` field, we are collecting the min, max, and
  252. sum of the temperature. For `voltage`, we are collecting the average.
  253. When the job is created, you receive the following results:
  254. [source,console-result]
  255. ----
  256. {
  257. "acknowledged": true
  258. }
  259. ----