simulate_pipeline.asciidoc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. [[java-rest-high-ingest-simulate-pipeline]]
  2. === Simulate Pipeline API
  3. [[java-rest-high-ingest-simulate-pipeline-request]]
  4. ==== Simulate Pipeline Request
  5. A `SimulatePipelineRequest` requires a source and a `XContentType`. The source consists
  6. of the request body. See the https://www.elastic.co/guide/en/elasticsearch/reference/master/simulate-pipeline-api.html[docs]
  7. for more details on the request body.
  8. ["source","java",subs="attributes,callouts,macros"]
  9. --------------------------------------------------
  10. include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-request]
  11. --------------------------------------------------
  12. <1> The request body as a `ByteArray`.
  13. <2> The XContentType for the request body supplied above.
  14. ==== Optional arguments
  15. The following arguments can optionally be provided:
  16. ["source","java",subs="attributes,callouts,macros"]
  17. --------------------------------------------------
  18. include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-request-pipeline-id]
  19. --------------------------------------------------
  20. <1> You can either specify an existing pipeline to execute against the provided documents, or supply a
  21. pipeline definition in the body of the request. This option sets the id for an existing pipeline.
  22. ["source","java",subs="attributes,callouts,macros"]
  23. --------------------------------------------------
  24. include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-request-verbose]
  25. --------------------------------------------------
  26. <1> To see the intermediate results of each processor in the simulate request, you can add the verbose parameter
  27. to the request.
  28. [[java-rest-high-ingest-simulate-pipeline-sync]]
  29. ==== Synchronous Execution
  30. ["source","java",subs="attributes,callouts,macros"]
  31. --------------------------------------------------
  32. include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-execute]
  33. --------------------------------------------------
  34. <1> Execute the request and get back the response in a `SimulatePipelineResponse` object.
  35. [[java-rest-high-ingest-simulate-pipeline-async]]
  36. ==== Asynchronous Execution
  37. The asynchronous execution of a simulate pipeline request requires both the `SimulatePipelineRequest`
  38. instance and an `ActionListener` instance to be passed to the asynchronous
  39. method:
  40. ["source","java",subs="attributes,callouts,macros"]
  41. --------------------------------------------------
  42. include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-execute-async]
  43. --------------------------------------------------
  44. <1> The `SimulatePipelineRequest` to execute and the `ActionListener` to use when
  45. the execution completes
  46. The asynchronous method does not block and returns immediately. Once it is
  47. completed the `ActionListener` is called back using the `onResponse` method
  48. if the execution successfully completed or using the `onFailure` method if
  49. it failed.
  50. A typical listener for `SimulatePipelineResponse` looks like:
  51. ["source","java",subs="attributes,callouts,macros"]
  52. --------------------------------------------------
  53. include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-execute-listener]
  54. --------------------------------------------------
  55. <1> Called when the execution is successfully completed. The response is
  56. provided as an argument
  57. <2> Called in case of failure. The raised exception is provided as an argument
  58. [[java-rest-high-ingest-simulate-pipeline-response]]
  59. ==== Simulate Pipeline Response
  60. The returned `SimulatePipelineResponse` allows to retrieve information about the executed
  61. operation as follows:
  62. ["source","java",subs="attributes,callouts,macros"]
  63. --------------------------------------------------
  64. include-tagged::{doc-tests}/IngestClientDocumentationIT.java[simulate-pipeline-response]
  65. --------------------------------------------------
  66. <1> Get results for each of the documents provided as instance of `List<SimulateDocumentResult>`.
  67. <2> If the request was in verbose mode cast the response to `SimulateDocumentVerboseResult`.
  68. <3> Check the result after each processor is applied.
  69. <4> Get the ingest document for the result obtained in 3.
  70. <5> Or get the failure for the result obtained in 3.
  71. <6> Get the result as `SimulateDocumentBaseResult` if the result was not verbose.
  72. <7> Get the ingest document for the result obtained in 6.
  73. <8> Or get the failure for the result obtained in 6.