put-watch.asciidoc 2.2 KB

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