put_job.asciidoc 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. [[java-rest-high-x-pack-rollup-put-job]]
  2. === Put Rollup Job API
  3. The Put Rollup Job API can be used to create a new Rollup job
  4. in the cluster. The API accepts a `PutRollupJobRequest` object
  5. as a request and returns a `PutRollupJobResponse`.
  6. [[java-rest-high-x-pack-rollup-put-rollup-job-request]]
  7. ==== Put Rollup Job Request
  8. A `PutRollupJobRequest` requires the following argument:
  9. ["source","java",subs="attributes,callouts,macros"]
  10. --------------------------------------------------
  11. include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-request]
  12. --------------------------------------------------
  13. <1> The configuration of the Rollup job to create as a `RollupJobConfig`
  14. [[java-rest-high-x-pack-rollup-put-rollup-job-config]]
  15. ==== Rollup Job Configuration
  16. The `RollupJobConfig` object contains all the details about the rollup job
  17. configuration. See {ref}/rollup-job-config.html[Rollup configuration] to learn more
  18. about the various configuration settings.
  19. A `RollupJobConfig` requires the following arguments:
  20. ["source","java",subs="attributes,callouts,macros"]
  21. --------------------------------------------------
  22. include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-config]
  23. --------------------------------------------------
  24. <1> The name of the Rollup job
  25. <2> The index (or index pattern) to rollup
  26. <3> The index to store rollup results into
  27. <4> A cron expression which defines when the Rollup job should be executed
  28. <5> The page size to use for the Rollup job
  29. <6> The grouping configuration of the Rollup job as a `GroupConfig`
  30. <7> The metrics configuration of the Rollup job as a list of `MetricConfig`
  31. <8> The timeout value to use for the Rollup job as a `TimeValue`
  32. [[java-rest-high-x-pack-rollup-put-rollup-job-group-config]]
  33. ==== Grouping Configuration
  34. The grouping configuration of the Rollup job is defined in the `RollupJobConfig`
  35. using a `GroupConfig` instance. `GroupConfig` reflects all the configuration
  36. settings that can be defined using the REST API. See {ref}/rollup-job-config.html#rollup-groups-config[Grouping Config]
  37. to learn more about these settings.
  38. Using the REST API, we could define this grouping configuration:
  39. [source,js]
  40. --------------------------------------------------
  41. "groups" : {
  42. "date_histogram": {
  43. "field": "timestamp",
  44. "interval": "1h",
  45. "delay": "7d",
  46. "time_zone": "UTC"
  47. },
  48. "terms": {
  49. "fields": ["hostname", "datacenter"]
  50. },
  51. "histogram": {
  52. "fields": ["load", "net_in", "net_out"],
  53. "interval": 5
  54. }
  55. }
  56. --------------------------------------------------
  57. // NOTCONSOLE
  58. Using the `GroupConfig` object and the high level REST client, the same
  59. configuration would be:
  60. ["source","java",subs="attributes,callouts,macros"]
  61. --------------------------------------------------
  62. include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-group-config]
  63. --------------------------------------------------
  64. <1> The date histogram aggregation to use to rollup up documents, as a `DateHistogramGroupConfig`
  65. <2> The terms aggregation to use to rollup up documents, as a `TermsGroupConfig`
  66. <3> The histogram aggregation to use to rollup up documents, as a `HistogramGroupConfig`
  67. <4> The grouping configuration as a `GroupConfig`
  68. [[java-rest-high-x-pack-rollup-put-rollup-job-metrics-config]]
  69. ==== Metrics Configuration
  70. After defining which groups should be generated for the data, you next configure
  71. which metrics should be collected. The list of metrics is defined in the `RollupJobConfig`
  72. using a `List<MetricConfig>` instance. `MetricConfig` reflects all the configuration
  73. settings that can be defined using the REST API. See {ref}/rollup-job-config.html#rollup-metrics-config[Metrics Config]
  74. to learn more about these settings.
  75. Using the REST API, we could define this metrics configuration:
  76. [source,js]
  77. --------------------------------------------------
  78. "metrics": [
  79. {
  80. "field": "temperature",
  81. "metrics": ["min", "max", "sum"]
  82. },
  83. {
  84. "field": "voltage",
  85. "metrics": ["avg", "value_count"]
  86. }
  87. ]
  88. --------------------------------------------------
  89. // NOTCONSOLE
  90. Using the `MetricConfig` object and the high level REST client, the same
  91. configuration would be:
  92. ["source","java",subs="attributes,callouts,macros"]
  93. --------------------------------------------------
  94. include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-metrics-config]
  95. --------------------------------------------------
  96. <1> The list of `MetricConfig` to configure in the `RollupJobConfig`
  97. <2> Adds the metrics to compute on the `temperature` field
  98. <3> Adds the metrics to compute on the `voltage` field
  99. By default, metrics `min`/`max` for the fields in `DateHistogramGroupConfig` and
  100. `HistogramGroupConfig` are added to the configuration unless the user already provided
  101. metrics for those fields.
  102. So, for the following configuration:
  103. [source,js]
  104. --------------------------------------------------
  105. "groups" : {
  106. "date_histogram": {
  107. "field": "timestamp",
  108. "interval": "1h",
  109. "delay": "7d",
  110. "time_zone": "UTC"
  111. },
  112. "terms": {
  113. "fields": ["hostname", "datacenter"]
  114. },
  115. "histogram": {
  116. "fields": ["load", "net_in", "net_out"],
  117. "interval": 5
  118. },
  119. },
  120. "metrics": [
  121. {
  122. "field": "load",
  123. "metrics": ["max"]
  124. },
  125. {
  126. "field": "net_in",
  127. "metrics": ["max"]
  128. }
  129. ]
  130. --------------------------------------------------
  131. // NOTCONSOLE
  132. The following will be the metrics in the configuration after
  133. the defaults are added server side. Note the default metrics
  134. provided for the fields `timestamp` and `net_out`
  135. [source,js]
  136. --------------------------------------------------
  137. "metrics": [
  138. {
  139. "field": "load",
  140. "metrics": ["max"]
  141. },
  142. {
  143. "field": "net_in",
  144. "metrics": ["max"]
  145. },
  146. {
  147. "field": "timestamp",
  148. "metrics": ["min", "max"]
  149. },
  150. {
  151. "field": "net_out",
  152. "metrics": ["min", "max"]
  153. }
  154. ]
  155. --------------------------------------------------
  156. // NOTCONSOLE
  157. [[java-rest-high-x-pack-rollup-put-rollup-job-execution]]
  158. ==== Execution
  159. The Put Rollup Job API can be executed through a `RollupClient`
  160. instance. Such instance can be retrieved from a `RestHighLevelClient`
  161. using the `rollup()` method:
  162. ["source","java",subs="attributes,callouts,macros"]
  163. --------------------------------------------------
  164. include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-execute]
  165. --------------------------------------------------
  166. [[java-rest-high-x-pack-rollup-put-rollup-job-response]]
  167. ==== Response
  168. The returned `PutRollupJobResponse` indicates if the new Rollup job
  169. has been successfully created:
  170. ["source","java",subs="attributes,callouts,macros"]
  171. --------------------------------------------------
  172. include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-response]
  173. --------------------------------------------------
  174. <1> `acknowledged` is a boolean indicating whether the job was successfully created
  175. [[java-rest-high-x-pack-rollup-put-rollup-job-async]]
  176. ==== Asynchronous Execution
  177. This request can be executed asynchronously:
  178. ["source","java",subs="attributes,callouts,macros"]
  179. --------------------------------------------------
  180. include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-execute-async]
  181. --------------------------------------------------
  182. <1> The `PutRollupJobRequest` to execute and the `ActionListener` to use when
  183. the execution completes
  184. The asynchronous method does not block and returns immediately. Once it is
  185. completed the `ActionListener` is called back using the `onResponse` method
  186. if the execution successfully completed or using the `onFailure` method if
  187. it failed.
  188. A typical listener for `PutRollupJobResponse` looks like:
  189. ["source","java",subs="attributes,callouts,macros"]
  190. --------------------------------------------------
  191. include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-execute-listener]
  192. --------------------------------------------------
  193. <1> Called when the execution is successfully completed. The response is
  194. provided as an argument
  195. <2> Called in case of failure. The raised exception is provided as an argument