put-job.asciidoc 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. [[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. [[rollup-groups-config]]
  50. `groups`::
  51. (Required, object) Defines the grouping fields and aggregations that are
  52. defined for this {rollup-job}. These fields will then be available later for
  53. aggregating into buckets.
  54. +
  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. There are three types of groupings currently available:
  63. --
  64. `date_histogram`:::
  65. (Required, object) A date histogram group aggregates a `date` field into
  66. time-based buckets. This group is *mandatory*; you currently cannot rollup
  67. documents without a timestamp and a `date_histogram` group. The
  68. `date_histogram` group has several parameters:
  69. `field`::::
  70. (Required, string) The date field that is to be rolled up.
  71. `calendar_interval` or `fixed_interval`::::
  72. (Required, <<time-units,time units>>) The interval of time buckets to be
  73. generated when rolling up. For example, `60m` produces 60 minute (hourly)
  74. rollups. This follows standard time formatting syntax as used elsewhere in
  75. {es}. The interval defines the _minimum_ interval that can be aggregated only.
  76. If hourly (`60m`) intervals are configured, <<rollup-search,rollup search>>
  77. can execute aggregations with 60m or greater (weekly, monthly, etc) intervals.
  78. So define the interval as the smallest unit that you wish to later query. For
  79. more information about the difference between calendar and fixed time
  80. intervals, see <<rollup-understanding-group-intervals>>.
  81. +
  82. --
  83. NOTE: Smaller, more granular intervals take up proportionally more space.
  84. --
  85. `delay`::::
  86. (Optional,<<time-units,time units>>) How long to wait before rolling up new
  87. documents. By default, the indexer attempts to roll up all data that is
  88. available. However, it is not uncommon for data to arrive out of order,
  89. sometimes even a few days late. The indexer is unable to deal with data that
  90. arrives after a time-span has been rolled up. That is to say, there is no
  91. provision to update already-existing rollups.
  92. +
  93. --
  94. Instead, you should specify a `delay` that matches the longest period of time
  95. you expect out-of-order data to arrive. For example, a `delay` of `1d`
  96. instructs the indexer to roll up documents up to `now - 1d`, which provides
  97. a day of buffer time for out-of-order documents to arrive.
  98. --
  99. `time_zone`::::
  100. (Optional, string) Defines what time_zone the rollup documents are stored as.
  101. Unlike raw data, which can shift timezones on the fly, rolled documents have
  102. to be stored with a specific timezone. By default, rollup documents are stored
  103. in `UTC`.
  104. `terms`:::
  105. (Optional, object) The terms group can be used on `keyword` or numeric fields
  106. to allow bucketing via the `terms` aggregation at a later point. The indexer
  107. enumerates and stores _all_ values of a field for each time-period. This can
  108. be potentially costly for high-cardinality groups such as IP addresses,
  109. especially if the time-bucket is particularly sparse.
  110. +
  111. --
  112. TIP: While it is unlikely that a rollup will ever be larger in size than the raw
  113. data, defining `terms` groups on multiple high-cardinality fields can
  114. effectively reduce the compression of a rollup to a large extent. You should be
  115. judicious which high-cardinality fields are included for that reason.
  116. The `terms` group has a single parameter:
  117. --
  118. `fields`::::
  119. (Required, string) The set of fields that you wish to collect terms for. This
  120. array can contain fields that are both `keyword` and numerics. Order does not
  121. matter.
  122. `histogram`:::
  123. (Optional, object) The histogram group aggregates one or more numeric fields
  124. into numeric histogram intervals.
  125. +
  126. --
  127. The `histogram` group has a two parameters:
  128. --
  129. `fields`::::
  130. (Required, array) The set of fields that you wish to build histograms for. All fields
  131. specified must be some kind of numeric. Order does not matter.
  132. `interval`::::
  133. (Required, integer) The interval of histogram buckets to be generated when
  134. rolling up. For example, a value of `5` creates buckets that are five units
  135. wide (`0-5`, `5-10`, etc). Note that only one interval can be specified in the
  136. `histogram` group, meaning that all fields being grouped via the histogram
  137. must share the same interval.
  138. `index_pattern`::
  139. (Required, string) The index or index pattern to roll up. Supports
  140. wildcard-style patterns (`logstash-*`). The job will
  141. attempt to rollup the entire index or index-pattern.
  142. +
  143. --
  144. NOTE: The `index_pattern` cannot be a pattern that would also match the
  145. destination `rollup_index`. For example, the pattern `foo-*` would match the
  146. rollup index `foo-rollup`. This situation would cause problems because the
  147. {rollup-job} would attempt to rollup its own data at runtime. If you attempt to
  148. configure a pattern that matches the `rollup_index`, an exception occurs to
  149. prevent this behavior.
  150. --
  151. [[rollup-metrics-config]]
  152. `metrics`::
  153. (Optional, object) Defines the metrics to collect for each grouping tuple.
  154. By default, only the doc_counts are collected for each group. To make rollup
  155. useful, you will often add metrics like averages, mins, maxes, etc. Metrics
  156. are defined on a per-field basis and for each field you configure which metric
  157. should be collected.
  158. +
  159. --
  160. The `metrics` configuration accepts an array of objects, where each object has
  161. two parameters:
  162. --
  163. `field`:::
  164. (Required, string) The field to collect metrics for. This must be a numeric
  165. of some kind.
  166. `metrics`:::
  167. (Required, array) An array of metrics to collect for the field. At least one
  168. metric must be configured. Acceptable metrics are `min`,`max`,`sum`,`avg`, and
  169. `value_count`.
  170. `page_size`::
  171. (Required, integer) The number of bucket results that are processed on each
  172. iteration of the rollup indexer. A larger value tends to execute faster, but
  173. requires more memory during processing. This value has no effect on how the
  174. data is rolled up; it is merely used for tweaking the speed or memory cost of
  175. the indexer.
  176. `rollup_index`::
  177. (Required, string) The index that contains the rollup results. The index can
  178. be shared with other {rollup-jobs}. The data is stored so that it doesn't
  179. interfere with unrelated jobs.
  180. [[rollup-put-job-api-example]]
  181. ==== {api-example-title}
  182. The following example creates a {rollup-job} named `sensor`, targeting the
  183. `sensor-*` index pattern:
  184. [source,console]
  185. --------------------------------------------------
  186. PUT _rollup/job/sensor
  187. {
  188. "index_pattern": "sensor-*",
  189. "rollup_index": "sensor_rollup",
  190. "cron": "*/30 * * * * ?",
  191. "page_size" :1000,
  192. "groups" : { <1>
  193. "date_histogram": {
  194. "field": "timestamp",
  195. "fixed_interval": "1h",
  196. "delay": "7d"
  197. },
  198. "terms": {
  199. "fields": ["node"]
  200. }
  201. },
  202. "metrics": [ <2>
  203. {
  204. "field": "temperature",
  205. "metrics": ["min", "max", "sum"]
  206. },
  207. {
  208. "field": "voltage",
  209. "metrics": ["avg"]
  210. }
  211. ]
  212. }
  213. --------------------------------------------------
  214. // TEST[setup:sensor_index]
  215. <1> This configuration enables date histograms to be used on the `timestamp`
  216. field and `terms` aggregations to be used on the `node` field.
  217. <2> This configuration defines metrics over two fields: `temperature` and
  218. `voltage`. For the `temperature` field, we are collecting the min, max, and
  219. sum of the temperature. For `voltage`, we are collecting the average.
  220. When the job is created, you receive the following results:
  221. [source,console-result]
  222. ----
  223. {
  224. "acknowledged": true
  225. }
  226. ----