put-job.asciidoc 10 KB

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