put_job.asciidoc 6.7 KB

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