Skip to content

Commit abdd276

Browse files
authored
Add query watches api to retrieve multiple watches. (#65813)
Backport #64582 to 7.x branch. This api supports pagination (from / size) and querying and sorting by watch _id and watcher metadata. This avoids using .watch index directly. On a per watch basis the same information that the get watch api returns is returned, except version. Relates #62501
1 parent 4bc6d2a commit abdd276

File tree

13 files changed

+1111
-11
lines changed

13 files changed

+1111
-11
lines changed

x-pack/docs/en/rest-api/watcher.asciidoc

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* <<watcher-api-put-watch>>
66
* <<watcher-api-get-watch>>
7+
* <<watcher-api-query-watches>>
78
* <<watcher-api-delete-watch>>
89
* <<watcher-api-execute-watch>>
910
* <<watcher-api-ack-watch>>
@@ -26,9 +27,11 @@ include::watcher/execute-watch.asciidoc[]
2627
//GET
2728
include::watcher/get-watch.asciidoc[]
2829
include::watcher/stats.asciidoc[]
30+
//QUERY
31+
include::watcher/query-watches.asciidoc[]
2932
//PUT
3033
include::watcher/put-watch.asciidoc[]
3134
//START
3235
include::watcher/start.asciidoc[]
3336
//STOP
34-
include::watcher/stop.asciidoc[]
37+
include::watcher/stop.asciidoc[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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

Comments
 (0)