get_script.asciidoc 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. [[java-rest-high-get-stored-script]]
  2. === Get Stored Script API
  3. [[java-rest-high-get-stored-script-request]]
  4. ==== Get Stored Script Request
  5. A `GetStoredScriptRequest` requires an `id`:
  6. ["source","java",subs="attributes,callouts,macros"]
  7. --------------------------------------------------
  8. include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-request]
  9. --------------------------------------------------
  10. <1> The id of the script
  11. ==== Optional arguments
  12. The following arguments can optionally be provided:
  13. ["source","java",subs="attributes,callouts,macros"]
  14. --------------------------------------------------
  15. include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-request-masterTimeout]
  16. --------------------------------------------------
  17. <1> Timeout to connect to the master node as a `TimeValue`
  18. <2> Timeout to connect to the master node as a `String`
  19. [[java-rest-high-get-stored-script-sync]]
  20. ==== Synchronous Execution
  21. ["source","java",subs="attributes,callouts,macros"]
  22. --------------------------------------------------
  23. include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-execute]
  24. --------------------------------------------------
  25. [[java-rest-high-get-stored-script-async]]
  26. ==== Asynchronous Execution
  27. The asynchronous execution of a get stored script request requires both the `GetStoredScriptRequest`
  28. instance and an `ActionListener` instance to be passed to the asynchronous method:
  29. ["source","java",subs="attributes,callouts,macros"]
  30. --------------------------------------------------
  31. include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-execute-async]
  32. --------------------------------------------------
  33. <1> The `GetStoredScriptRequest` to execute and the `ActionListener` to use when
  34. the execution completes
  35. [[java-rest-high-get-stored-script-listener]]
  36. ===== Action Listener
  37. The asynchronous method does not block and returns immediately. Once it is
  38. completed the `ActionListener` is called back using the `onResponse` method
  39. if the execution successfully completed or using the `onFailure` method if
  40. it failed.
  41. A typical listener for `GetStoredScriptResponse` looks like:
  42. ["source","java",subs="attributes,callouts,macros"]
  43. --------------------------------------------------
  44. include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-execute-listener]
  45. --------------------------------------------------
  46. <1> Called when the execution is successfully completed. The response is
  47. provided as an argument
  48. <2> Called in case of failure. The raised exception is provided as an argument
  49. [[java-rest-high-get-stored-script-response]]
  50. ==== Get Stored Script Response
  51. The returned `GetStoredScriptResponse` allows to retrieve information about the
  52. executed operation as follows:
  53. ["source","java",subs="attributes,callouts,macros"]
  54. --------------------------------------------------
  55. include-tagged::{doc-tests}/StoredScriptsDocumentationIT.java[get-stored-script-response]
  56. --------------------------------------------------
  57. <1> The script object consists of a content and a metadata
  58. <2> The language the script is written in, which defaults to `painless`.
  59. <3> The content of the script
  60. <4> Any named options that should be passed into the script.