post-data.asciidoc 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. [[java-rest-high-x-pack-ml-post-data]]
  2. === Post Data API
  3. The Post Data API provides the ability to post data to an open
  4. {ml} job in the cluster.
  5. It accepts a `PostDataRequest` object and responds
  6. with a `PostDataResponse` object.
  7. [[java-rest-high-x-pack-ml-post-data-request]]
  8. ==== Post Data Request
  9. A `PostDataRequest` object gets created with an existing non-null `jobId`
  10. and the `XContentType` being sent. Individual docs can be added
  11. incrementally via the `PostDataRequest.JsonBuilder#addDoc` method.
  12. These are then serialized and sent in bulk when passed to the `PostDataRequest`.
  13. Alternatively, the serialized bulk content can be set manually, along with its `XContentType`
  14. through one of the other `PostDataRequest` constructors.
  15. Only `XContentType.JSON` and `XContentType.SMILE` are supported.
  16. ["source","java",subs="attributes,callouts,macros"]
  17. --------------------------------------------------
  18. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-post-data-request]
  19. --------------------------------------------------
  20. <1> Create a new `PostDataRequest.JsonBuilder` object for incrementally adding documents
  21. <2> Add a new document as a `Map<String, Object>` object
  22. <3> Add a new document as a serialized JSON formatted String.
  23. <4> Constructing a new request referencing an opened `jobId`, and a JsonBuilder
  24. ==== Optional Arguments
  25. The following arguments are optional.
  26. ["source","java",subs="attributes,callouts,macros"]
  27. --------------------------------------------------
  28. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-post-data-request-options]
  29. --------------------------------------------------
  30. <1> Set the start of the bucket resetting time
  31. <2> Set the end of the bucket resetting time
  32. [[java-rest-high-x-pack-ml-post-data-execution]]
  33. ==== Execution
  34. The request can be executed through the `MachineLearningClient` contained
  35. in the `RestHighLevelClient` object, accessed via the `machineLearningClient()` method.
  36. ["source","java",subs="attributes,callouts,macros"]
  37. --------------------------------------------------
  38. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-post-data-execute]
  39. --------------------------------------------------
  40. [[java-rest-high-x-pack-ml-post-data-execution-async]]
  41. ==== Asynchronous Execution
  42. The request can also be executed asynchronously:
  43. ["source","java",subs="attributes,callouts,macros"]
  44. --------------------------------------------------
  45. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-post-data-execute-async]
  46. --------------------------------------------------
  47. <1> The `PostDataRequest` to execute and the `ActionListener` to use when
  48. the execution completes
  49. The method does not block and returns immediately. The passed `ActionListener` is used
  50. to notify the caller of completion. A typical `ActionListener` for `PostDataResponse` may
  51. look like
  52. ["source","java",subs="attributes,callouts,macros"]
  53. --------------------------------------------------
  54. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-post-data-listener]
  55. --------------------------------------------------
  56. <1> `onResponse` is called back when the action is completed successfully
  57. <2> `onFailure` is called back when some unexpected error occurs
  58. [[java-rest-high-x-pack-ml-post-data-response]]
  59. ==== Post Data Response
  60. A `PostDataResponse` contains current data processing statistics.
  61. ["source","java",subs="attributes,callouts,macros"]
  62. --------------------------------------------------
  63. include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-post-data-response]
  64. --------------------------------------------------
  65. <1> `getDataCounts()` a `DataCounts` object containing the current
  66. data processing counts.