put-job.asciidoc 10 KB

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