put-datafeed.asciidoc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. [[java-rest-high-x-pack-ml-put-datafeed]]
  2. === Put Datafeed API
  3. The Put Datafeed API can be used to create a new {ml} datafeed
  4. in the cluster. The API accepts a `PutDatafeedRequest` object
  5. as a request and returns a `PutDatafeedResponse`.
  6. [[java-rest-high-x-pack-ml-put-datafeed-request]]
  7. ==== Put Datafeed Request
  8. A `PutDatafeedRequest` requires the following argument:
  9. ["source","java",subs="attributes,callouts,macros"]
  10. --------------------------------------------------
  11. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-put-datafeed-request]
  12. --------------------------------------------------
  13. <1> The configuration of the {ml} datafeed to create
  14. [[java-rest-high-x-pack-ml-put-datafeed-config]]
  15. ==== Datafeed Configuration
  16. The `DatafeedConfig` object contains all the details about the {ml} datafeed
  17. configuration.
  18. A `DatafeedConfig` requires the following arguments:
  19. ["source","java",subs="attributes,callouts,macros"]
  20. --------------------------------------------------
  21. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-create-datafeed-config]
  22. --------------------------------------------------
  23. <1> The datafeed ID and the job ID
  24. <2> The indices that contain the data to retrieve and feed into the job
  25. ==== Optional Arguments
  26. The following arguments are optional:
  27. ["source","java",subs="attributes,callouts,macros"]
  28. --------------------------------------------------
  29. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-create-datafeed-config-set-chunking-config]
  30. --------------------------------------------------
  31. <1> Specifies how data searches are split into time chunks.
  32. ["source","java",subs="attributes,callouts,macros"]
  33. --------------------------------------------------
  34. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-create-datafeed-config-set-frequency]
  35. --------------------------------------------------
  36. <1> The interval at which scheduled queries are made while the datafeed runs in real time.
  37. ["source","java",subs="attributes,callouts,macros"]
  38. --------------------------------------------------
  39. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-create-datafeed-config-set-query]
  40. --------------------------------------------------
  41. <1> A query to filter the search results by. Defaults to the `match_all` query.
  42. ["source","java",subs="attributes,callouts,macros"]
  43. --------------------------------------------------
  44. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-create-datafeed-config-set-query-delay]
  45. --------------------------------------------------
  46. <1> The time interval behind real time that data is queried.
  47. ["source","java",subs="attributes,callouts,macros"]
  48. --------------------------------------------------
  49. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-create-datafeed-config-set-script-fields]
  50. --------------------------------------------------
  51. <1> Allows the use of script fields.
  52. ["source","java",subs="attributes,callouts,macros"]
  53. --------------------------------------------------
  54. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-create-datafeed-config-set-scroll-size]
  55. --------------------------------------------------
  56. <1> The `size` parameter used in the searches.
  57. [[java-rest-high-x-pack-ml-put-datafeed-execution]]
  58. ==== Execution
  59. The Put Datafeed API can be executed through a `MachineLearningClient`
  60. instance. Such an instance can be retrieved from a `RestHighLevelClient`
  61. using the `machineLearning()` method:
  62. ["source","java",subs="attributes,callouts,macros"]
  63. --------------------------------------------------
  64. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-put-datafeed-execute]
  65. --------------------------------------------------
  66. [[java-rest-high-x-pack-ml-put-datafeed-response]]
  67. ==== Response
  68. The returned `PutDatafeedResponse` returns the full representation of
  69. the new {ml} datafeed if it has been successfully created. This will
  70. contain the creation time and other fields initialized using
  71. default values:
  72. ["source","java",subs="attributes,callouts,macros"]
  73. --------------------------------------------------
  74. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-put-datafeed-response]
  75. --------------------------------------------------
  76. <1> The created datafeed
  77. [[java-rest-high-x-pack-ml-put-datafeed-async]]
  78. ==== Asynchronous Execution
  79. This request can be executed asynchronously:
  80. ["source","java",subs="attributes,callouts,macros"]
  81. --------------------------------------------------
  82. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-put-datafeed-execute-async]
  83. --------------------------------------------------
  84. <1> The `PutDatafeedRequest` to execute and the `ActionListener` to use when
  85. the execution completes
  86. The asynchronous method does not block and returns immediately. Once it is
  87. completed the `ActionListener` is called back using the `onResponse` method
  88. if the execution successfully completed or using the `onFailure` method if
  89. it failed.
  90. A typical listener for `PutDatafeedResponse` looks like:
  91. ["source","java",subs="attributes,callouts,macros"]
  92. --------------------------------------------------
  93. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-put-datafeed-execute-listener]
  94. --------------------------------------------------
  95. <1> Called when the execution is successfully completed. The response is
  96. provided as an argument
  97. <2> Called in case of failure. The raised exception is provided as an argument