2017-03-28 17:23:01 -04:00
|
|
|
[float]
|
|
|
|
[[api-java-get-watch]]
|
2019-09-30 13:18:50 -04:00
|
|
|
=== Get watch API
|
2017-03-28 17:23:01 -04:00
|
|
|
|
|
|
|
This API retrieves a watch by its id.
|
|
|
|
|
|
|
|
The following example gets a watch with `my-watch` id:
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
GetWatchResponse getWatchResponse = watcherClient.prepareGetWatch("my-watch").get();
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
You can access the watch definition by accessing the source of the response:
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
XContentSource source = getWatchResponse.getSource();
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
The `XContentSource` provides you methods to explore the source:
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
Map<String, Object> map = source.getAsMap();
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
Or get a specific value associated with a known key:
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
String host = source.getValue("input.http.request.host");
|
|
|
|
--------------------------------------------------
|