put_job.asciidoc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. "calendar_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. [[java-rest-high-x-pack-rollup-put-rollup-job-execution]]
  100. ==== Execution
  101. The Put Rollup Job API can be executed through a `RollupClient`
  102. instance. Such instance can be retrieved from a `RestHighLevelClient`
  103. using the `rollup()` method:
  104. ["source","java",subs="attributes,callouts,macros"]
  105. --------------------------------------------------
  106. include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-execute]
  107. --------------------------------------------------
  108. [[java-rest-high-x-pack-rollup-put-rollup-job-response]]
  109. ==== Response
  110. The returned `PutRollupJobResponse` indicates if the new Rollup job
  111. has been successfully created:
  112. ["source","java",subs="attributes,callouts,macros"]
  113. --------------------------------------------------
  114. include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-response]
  115. --------------------------------------------------
  116. <1> `acknowledged` is a boolean indicating whether the job was successfully created
  117. [[java-rest-high-x-pack-rollup-put-rollup-job-async]]
  118. ==== Asynchronous Execution
  119. This request can be executed asynchronously:
  120. ["source","java",subs="attributes,callouts,macros"]
  121. --------------------------------------------------
  122. include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-execute-async]
  123. --------------------------------------------------
  124. <1> The `PutRollupJobRequest` to execute and the `ActionListener` to use when
  125. the execution completes
  126. The asynchronous method does not block and returns immediately. Once it is
  127. completed the `ActionListener` is called back using the `onResponse` method
  128. if the execution successfully completed or using the `onFailure` method if
  129. it failed.
  130. A typical listener for `PutRollupJobResponse` looks like:
  131. ["source","java",subs="attributes,callouts,macros"]
  132. --------------------------------------------------
  133. include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-execute-listener]
  134. --------------------------------------------------
  135. <1> Called when the execution is successfully completed. The response is
  136. provided as an argument
  137. <2> Called in case of failure. The raised exception is provided as an argument