get-watch.asciidoc 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. [float]
  2. [[api-java-get-watch]]
  3. === Get Watch API
  4. This API retrieves a watch by its id.
  5. The following example gets a watch with `my-watch` id:
  6. [source,java]
  7. --------------------------------------------------
  8. GetWatchResponse getWatchResponse = watcherClient.prepareGetWatch("my-watch").get();
  9. --------------------------------------------------
  10. You can access the watch definition by accessing the source of the response:
  11. [source,java]
  12. --------------------------------------------------
  13. XContentSource source = getWatchResponse.getSource();
  14. --------------------------------------------------
  15. The `XContentSource` provides you methods to explore the source:
  16. [source,java]
  17. --------------------------------------------------
  18. Map<String, Object> map = source.getAsMap();
  19. --------------------------------------------------
  20. Or get a specific value associated with a known key:
  21. [source,java]
  22. --------------------------------------------------
  23. String host = source.getValue("input.http.request.host");
  24. --------------------------------------------------