put_job.asciidoc 6.8 KB

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