put-job.asciidoc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[rollup-put-job]]
  4. === Create Job API
  5. ++++
  6. <titleabbrev>Create Job</titleabbrev>
  7. ++++
  8. experimental[]
  9. This API enables you to create a rollup job. The job will be created in a `STOPPED` state, and must be
  10. started with the <<rollup-start-job,Start Job API>>.
  11. ==== Request
  12. `PUT _xpack/rollup/job/<job_id>`
  13. //===== Description
  14. ==== Path Parameters
  15. `job_id` (required)::
  16. (string) Identifier for the job
  17. ==== Request Body
  18. `index_pattern` (required)::
  19. (string) The index, or index pattern, that you wish to rollup. Supports wildcard-style patterns (`logstash-*`).
  20. `rollup_index` (required)::
  21. (string) The index that you wish to store rollup results into. Can be shared with other rollup jobs.
  22. `cron` (required)::
  23. (string) A cron string which defines when the rollup job should be executed.
  24. `page_size` (required)::
  25. (int) The number of bucket results that should be processed on each iteration of the rollup indexer. A larger value
  26. will tend to execute faster, but will require more memory during processing.
  27. `groups` (required)::
  28. (object) Defines the grouping fields that are defined for this rollup job. See <<rollup-job-config,rollup job config>>.
  29. `metrics`::
  30. (object) Defines the metrics that should be collected for each grouping tuple. See <<rollup-job-config,rollup job config>>.
  31. For more details about the job configuration, see <<rollup-job-config>>.
  32. ==== Authorization
  33. You must have `manage` or `manage_rollup` cluster privileges to use this API.
  34. For more information, see
  35. {xpack-ref}/security-privileges.html[Security Privileges].
  36. ==== Examples
  37. The following example creates a rollup job named "sensor", targeting the "sensor-*" index pattern:
  38. [source,js]
  39. --------------------------------------------------
  40. PUT _xpack/rollup/job/sensor
  41. {
  42. "index_pattern": "sensor-*",
  43. "rollup_index": "sensor_rollup",
  44. "cron": "*/30 * * * * ?",
  45. "page_size" :1000,
  46. "groups" : {
  47. "date_histogram": {
  48. "field": "timestamp",
  49. "interval": "60m",
  50. "delay": "7d"
  51. },
  52. "terms": {
  53. "fields": ["node"]
  54. }
  55. },
  56. "metrics": [
  57. {
  58. "field": "temperature",
  59. "metrics": ["min", "max", "sum"]
  60. },
  61. {
  62. "field": "voltage",
  63. "metrics": ["avg"]
  64. }
  65. ]
  66. }
  67. --------------------------------------------------
  68. // CONSOLE
  69. // TEST[setup:sensor_index]
  70. When the job is created, you receive the following results:
  71. [source,js]
  72. ----
  73. {
  74. "acknowledged": true
  75. }
  76. ----
  77. // TESTRESPONSE
  78. By default the metrics `min`/`max` are added
  79. for the fields in the `date_histogram` and `histogram` configurations.
  80. If this behavior is not desired, explicitly configure metrics
  81. for those fields. This will override the defaults.
  82. If the following is provided
  83. [source,js]
  84. --------------------------------------------------
  85. PUT _xpack/rollup/job/sensor2
  86. {
  87. "index_pattern": "sensor-*",
  88. "rollup_index": "sensor_rollup",
  89. "cron": "*/30 * * * * ?",
  90. "page_size" :1000,
  91. "groups" : {
  92. "date_histogram": {
  93. "field": "timestamp",
  94. "interval": "60m",
  95. "delay": "7d"
  96. },
  97. "histogram": {
  98. "fields": ["voltage", "temperature"],
  99. "interval": 5
  100. }
  101. },
  102. "metrics": [
  103. {
  104. "field": "temperature",
  105. "metrics": ["min", "max", "sum"]
  106. }
  107. ]
  108. }
  109. --------------------------------------------------
  110. // NOTCONSOLE
  111. // TEST[setup:sensor_index]
  112. The actual config when created in the cluster will look as follows.
  113. [source,js]
  114. --------------------------------------------------
  115. {
  116. "index_pattern": "sensor-*",
  117. "rollup_index": "sensor_rollup",
  118. "cron": "*/30 * * * * ?",
  119. "page_size" :1000,
  120. "groups" : {
  121. "date_histogram": {
  122. "field": "timestamp",
  123. "interval": "60m",
  124. "delay": "7d"
  125. },
  126. "histogram": {
  127. "fields": ["voltage", "temperature"],
  128. "interval": 5
  129. }
  130. },
  131. "metrics": [
  132. {
  133. "field": "temperature",
  134. "metrics": ["min", "max", "sum"]
  135. },
  136. {
  137. "field": "voltage", <1>
  138. "metrics": ["min", "max"]
  139. },
  140. {
  141. "field": "timestamp", <1>
  142. "metrics": ["min", "max"]
  143. }
  144. ]
  145. }
  146. --------------------------------------------------
  147. // NOTCONSOLE
  148. <1> Notice the new default metrics gathered for `voltage` and `timestamp`.
  149. Since these fields were referenced in `groups.histogram` and
  150. `groups.date_histogram` configurations
  151. respectively and no metrics were requested for them,
  152. they both got the default metrics of `["min", "max"]`.