|
| 1 | +[role="xpack"] |
| 2 | +[[watcher-api-query-watches]] |
| 3 | +=== Query watches API |
| 4 | +++++ |
| 5 | +<titleabbrev>Query watches</titleabbrev> |
| 6 | +++++ |
| 7 | + |
| 8 | +Retrieves all registered watches. |
| 9 | + |
| 10 | +[[watcher-api-query-watches-request]] |
| 11 | +==== {api-request-title} |
| 12 | + |
| 13 | +`GET /_watcher/_query/watches` |
| 14 | + |
| 15 | +[[watcher-api-query-watches-prereqs]] |
| 16 | +==== {api-prereq-title} |
| 17 | + |
| 18 | +* You must have `manage_watcher` or `monitor_watcher` cluster privileges to use |
| 19 | +this API. For more information, see <<security-privileges>>. |
| 20 | + |
| 21 | +//[[watcher-api-query-watches-desc]] |
| 22 | +//==== {api-description-title} |
| 23 | + |
| 24 | +Retrieves all watches in a paginated manner and |
| 25 | +optionally filtering watches by a query. |
| 26 | + |
| 27 | +//[[watcher-api-query-watches-request-body]] |
| 28 | +//==== {api-request-body-title} |
| 29 | + |
| 30 | +This API supports the following fields: |
| 31 | + |
| 32 | +[cols=",^,^,", options="header"] |
| 33 | +|====== |
| 34 | +| Name | Required | Default | Description |
| 35 | + |
| 36 | +| `from` | no | 0 | The offset from the first result to fetch. Needs to be non-negative. |
| 37 | + |
| 38 | +| `size` | no | 10 | The number of hits to return. Needs to be non-negative. |
| 39 | + |
| 40 | +| `query` | no | null | Optional, <<query-dsl,query>> filter watches to be returned. |
| 41 | + |
| 42 | +| `sort` | no | null | Optional <<search-request-sort,sort definition>>. |
| 43 | + |
| 44 | +| `search_after` | no | null | Optional <<search-request-search-after,search After>> to do pagination |
| 45 | + using last hit's sort values. |
| 46 | +|====== |
| 47 | + |
| 48 | +Note that only the `_id` and `metadata.*` fields are queryable or sortable. |
| 49 | + |
| 50 | +//[[watcher-api-query-watches-response-body]] |
| 51 | +//==== {api-response-body-title} |
| 52 | + |
| 53 | +This api returns the following top level fields: |
| 54 | + |
| 55 | +`count`:: |
| 56 | + The total number of watches found. |
| 57 | + |
| 58 | +`watches`:: |
| 59 | + A list of watches based on the `from`, `size` or `search_after` request body parameters. |
| 60 | + |
| 61 | +[[watcher-api-query-watches-example]] |
| 62 | +==== {api-examples-title} |
| 63 | + |
| 64 | +The following example list all stored watches: |
| 65 | + |
| 66 | +[source,console] |
| 67 | +-------------------------------------------------- |
| 68 | +GET /_watcher/_query/watches |
| 69 | +-------------------------------------------------- |
| 70 | +// TEST[setup:my_active_watch] |
| 71 | + |
| 72 | +Response: |
| 73 | + |
| 74 | +[source,console-result] |
| 75 | +-------------------------------------------------- |
| 76 | +{ |
| 77 | + "count": 1, |
| 78 | + "watches": [ |
| 79 | + { |
| 80 | + "_id": "my_watch", |
| 81 | + "watch": { |
| 82 | + "trigger": { |
| 83 | + "schedule": { |
| 84 | + "hourly": { |
| 85 | + "minute": [ |
| 86 | + 0, |
| 87 | + 5 |
| 88 | + ] |
| 89 | + } |
| 90 | + } |
| 91 | + }, |
| 92 | + "input": { |
| 93 | + "simple": { |
| 94 | + "payload": { |
| 95 | + "send": "yes" |
| 96 | + } |
| 97 | + } |
| 98 | + }, |
| 99 | + "condition": { |
| 100 | + "always": {} |
| 101 | + }, |
| 102 | + "actions": { |
| 103 | + "test_index": { |
| 104 | + "index": { |
| 105 | + "index": "test" |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + }, |
| 110 | + "status": { |
| 111 | + "state": { |
| 112 | + "active": true, |
| 113 | + "timestamp": "2015-05-26T18:21:08.630Z" |
| 114 | + }, |
| 115 | + "actions": { |
| 116 | + "test_index": { |
| 117 | + "ack": { |
| 118 | + "timestamp": "2015-05-26T18:21:08.630Z", |
| 119 | + "state": "awaits_successful_execution" |
| 120 | + } |
| 121 | + } |
| 122 | + }, |
| 123 | + "version": -1 |
| 124 | + }, |
| 125 | + "_seq_no": 0, |
| 126 | + "_primary_term": 1 |
| 127 | + } |
| 128 | + ] |
| 129 | +} |
| 130 | +-------------------------------------------------- |
| 131 | +// TESTRESPONSE[s/"timestamp": "2015-05-26T18:21:08.630Z"/"timestamp": "$body.watches.0.status.state.timestamp"/] |
0 commit comments