put-watch.asciidoc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. [role="xpack"]
  2. [[java-rest-high-x-pack-watcher-put-watch]]
  3. === Create or update watch API
  4. [[java-rest-high-x-pack-watcher-put-watch-execution]]
  5. ==== Execution
  6. General information about the installed {watcher} features can be retrieved
  7. using the `watcher()` method:
  8. ["source","java",subs="attributes,callouts,macros"]
  9. --------------------------------------------------
  10. include-tagged::{doc-tests}/WatcherDocumentationIT.java[x-pack-put-watch-execute]
  11. --------------------------------------------------
  12. <1> Allows to store the watch, but to not trigger it. Defaults to `true`
  13. [[java-rest-high-x-pack-watcher-put-watch-response]]
  14. ==== Response
  15. The returned `PutWatchResponse` contains `created`, `id`,
  16. and `version` information.
  17. ["source","java",subs="attributes,callouts,macros"]
  18. --------------------------------------------------
  19. include-tagged::{doc-tests}/WatcherDocumentationIT.java[x-pack-put-watch-response]
  20. --------------------------------------------------
  21. <1> `_id` contains id of the watch
  22. <2> `created` is a boolean indicating whether the watch was created for the first time
  23. <3> `_version` returns the newly created version
  24. [[java-rest-high-x-pack-watcher-put-watch-async]]
  25. ==== Asynchronous execution
  26. This request can be executed asynchronously:
  27. ["source","java",subs="attributes,callouts,macros"]
  28. --------------------------------------------------
  29. include-tagged::{doc-tests}/WatcherDocumentationIT.java[x-pack-put-watch-execute-async]
  30. --------------------------------------------------
  31. <1> The `PutWatchRequest` to execute and the `ActionListener` to use when
  32. the execution completes
  33. The asynchronous method does not block and returns immediately. Once it is
  34. completed the `ActionListener` is called back using the `onResponse` method
  35. if the execution successfully completed or using the `onFailure` method if
  36. it failed.
  37. A typical listener for `PutWatchResponse` looks like:
  38. ["source","java",subs="attributes,callouts,macros"]
  39. --------------------------------------------------
  40. include-tagged::{doc-tests}/WatcherDocumentationIT.java[x-pack-put-watch-execute-listener]
  41. --------------------------------------------------
  42. <1> Called when the execution is successfully completed. The response is
  43. provided as an argument
  44. <2> Called in case of failure. The raised exception is provided as an argument