submit.asciidoc 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. --
  2. :api: asyncsearch-submit
  3. :request: SubmitAsyncSearchRequest
  4. :response: AsyncSearchResponse
  5. --
  6. [role="xpack"]
  7. [id="{upid}-{api}"]
  8. === Submit Async Search API
  9. [id="{upid}-{api}-request"]
  10. ==== Request
  11. A +{request}+ allows to submit an asynchronous search task to
  12. the cluster. Required arguments are the `SearchSourceBuilder` defining
  13. the search and the target indices:
  14. ["source","java",subs="attributes,callouts,macros"]
  15. --------------------------------------------------
  16. include-tagged::{doc-tests-file}[{api}-request]
  17. --------------------------------------------------
  18. <1> The definition of the search to run
  19. <2> The target indices for the search
  20. ==== Optional arguments
  21. The following arguments can optionally be provided:
  22. ["source","java",subs="attributes,callouts,macros"]
  23. --------------------------------------------------
  24. include-tagged::{doc-tests-file}[{api}-request-arguments]
  25. --------------------------------------------------
  26. <1> The minimum time that the request should wait before
  27. returning a partial result (defaults to 1 second).
  28. <2> The expiration time of the request (defaults to 5 days).
  29. <3> Controls whether the results should be stored if the request
  30. completed within the provided `wait_for_completion` time (default: false)
  31. [id="{upid}-{api}-sync"]
  32. ==== Synchronous Execution
  33. ["source","java",subs="attributes,callouts,macros"]
  34. --------------------------------------------------
  35. include-tagged::{doc-tests-file}[{api}-execute]
  36. --------------------------------------------------
  37. <1> Execute the request and get back the response as an +{response}+ object.
  38. [id="{upid}-{api}-async"]
  39. ==== Asynchronous Execution
  40. The asynchronous execution of a +{request}+ allows to use an
  41. `ActionListener` to be called back when the submit request returns. Note
  42. that this is does not concern the execution of the submitted search request,
  43. which always executes asynchronously. The listener, however, waits for the
  44. submit request itself to come back:
  45. ["source","java",subs="attributes,callouts,macros"]
  46. --------------------------------------------------
  47. include-tagged::{doc-tests-file}[{api}-execute-async]
  48. --------------------------------------------------
  49. <1> The +{request}+ to execute and the `ActionListener` to use when
  50. the execution completes
  51. The asynchronous method does not block and returns immediately. Once it is
  52. completed the `ActionListener` is called back using the `onResponse` method
  53. if the execution successfully completed or using the `onFailure` method if
  54. it failed.
  55. A typical listener for +{response}+ looks like:
  56. ["source","java",subs="attributes,callouts,macros"]
  57. --------------------------------------------------
  58. include-tagged::{doc-tests-file}[{api}-listener]
  59. --------------------------------------------------
  60. <1> Called when the execution is successfully completed. The response is
  61. provided as an argument
  62. <2> Called in case of failure. The raised exception is provided as an argument
  63. [id="{upid}-{api}-response"]
  64. ==== Response
  65. The returned +{response}+ allows to retrieve information about the executed
  66. operation as follows:
  67. ["source","java",subs="attributes,callouts,macros"]
  68. --------------------------------------------------
  69. include-tagged::{doc-tests-file}[{api}-response]
  70. --------------------------------------------------
  71. <1> The `SearchResponse`, or `null` if not available yet
  72. <2> The id of the async search request, `null` if the response isn't stored
  73. <3> `true` when the response contains partial results
  74. <4> `true` when the search is still running
  75. <5> The time the response was created (millis since epoch)
  76. <6> The time the response expires (millis since epoch)
  77. <7> Get failure reasons or `null` for no failures