Create or update a watch
When a watch is registered, a new document that represents the watch is added to the .watches
index and its trigger is immediately registered with the relevant trigger engine.
Typically for the schedule
trigger, the scheduler is the trigger engine.
IMPORTANT: You must use Kibana or this API to create a watch.
Do not add a watch directly to the .watches
index by using the Elasticsearch index API.
If Elasticsearch security features are enabled, do not give users write privileges on the .watches
index.
When you add a watch you can also define its initial active state by setting the active parameter.
When Elasticsearch security features are enabled, your watch can index or search only on indices for which the user that stored the watch has privileges.
If the user is able to read index a
, but not index b
, the same will apply when the watch runs.
Path parameters
-
id
string Required The identifier for the watch.
Query parameters
-
active
boolean The initial state of the watch. The default value is
true
, which means the watch is active by default. -
if_primary_term
number only update the watch if the last operation that has changed the watch has the specified primary term
-
if_seq_no
number only update the watch if the last operation that has changed the watch has the specified sequence number
-
version
number Explicit version number for concurrency control
Body
-
actions
object The list of actions that will be run if the condition matches.
Hide actions attribute Show actions attribute object
-
*
object Additional properties Hide * attributes Show * attributes object
-
action_type
string Values are
email
,webhook
,index
,logging
,slack
, orpagerduty
. -
condition
object -
foreach
string -
max_iterations
number -
name
string -
throttle_period
string A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
throttle_period_in_millis
number Time unit for milliseconds
-
transform
object Hide transform attributes Show transform attributes object
-
chain
array[object] -
script
object Hide script attributes Show script attributes object
-
search
object Hide search attributes Show search attributes object
-
request
object Required Hide request attributes Show request attributes object
-
body
object Hide body attribute Show body attribute object
-
query
object Required An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
-
-
indices
array[string] -
indices_options
object Hide indices_options attributes Show indices_options attributes object
-
allow_no_indices
boolean If false, the request returns an error if any wildcard expression, index alias, or
_all
value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targetingfoo*,bar*
returns an error if an index starts withfoo
but no index starts withbar
. -
expand_wildcards
string | array[string] -
ignore_unavailable
boolean If true, missing or closed indices are not included in the response.
-
ignore_throttled
boolean If true, concrete, expanded or aliased indices are ignored when frozen.
-
-
search_type
string Values are
query_then_fetch
ordfs_query_then_fetch
. -
template
object Hide template attributes Show template attributes object
-
rest_total_hits_as_int
boolean
-
-
timeout
string Required A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
-
-
-
index
object Hide index attributes Show index attributes object
-
index
string Required -
doc_id
string -
refresh
string Values are
true
,false
, orwait_for
. -
op_type
string Values are
index
orcreate
. -
timeout
string A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
execution_time_field
string Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.
-
-
logging
object -
email
object Hide email attributes Show email attributes object
-
pagerduty
object Hide pagerduty attributes Show pagerduty attributes object
-
account
string -
attach_payload
boolean Required -
client
string -
client_url
string -
contexts
array[object] -
description
string Required -
event_type
string Values are
trigger
,resolve
, oracknowledge
. -
incident_key
string Required -
proxy
object
-
-
slack
object Hide slack attributes Show slack attributes object
-
account
string -
message
object Required Hide message attributes Show message attributes object
-
attachments
array[object] Required Hide attachments attributes Show attachments attributes object
-
author_icon
string -
author_link
string -
author_name
string Required -
color
string -
fallback
string -
fields
array[object] -
footer
string -
footer_icon
string -
image_url
string -
pretext
string -
text
string -
thumb_url
string -
title
string Required -
title_link
string
-
-
dynamic_attachments
object Hide dynamic_attachments attributes Show dynamic_attachments attributes object
-
attachment_template
object Required Hide attachment_template attributes Show attachment_template attributes object
-
author_icon
string -
author_link
string -
author_name
string Required -
color
string -
fallback
string -
fields
array[object] -
footer
string -
footer_icon
string -
image_url
string -
pretext
string -
text
string -
thumb_url
string -
title
string Required -
title_link
string
-
-
list_path
string Required
-
-
from
string Required -
icon
string -
text
string Required -
to
array[string] Required
-
-
-
webhook
object Hide webhook attributes Show webhook attributes object
-
auth
object -
body
string -
connection_timeout
string A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
headers
object Hide headers attribute Show headers attribute object
-
*
string Additional properties
-
-
host
string -
method
string Values are
head
,get
,post
,put
, ordelete
. -
params
object Hide params attribute Show params attribute object
-
*
string Additional properties
-
-
path
string -
port
number -
proxy
object -
read_timeout
string A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
scheme
string Values are
http
orhttps
. -
url
string
-
-
-
-
condition
object -
input
object Hide input attributes Show input attributes object
-
chain
object -
http
object Hide http attributes Show http attributes object
-
extract
array[string] -
request
object Hide request attributes Show request attributes object
-
auth
object -
body
string -
connection_timeout
string A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
headers
object Hide headers attribute Show headers attribute object
-
*
string Additional properties
-
-
host
string -
method
string Values are
head
,get
,post
,put
, ordelete
. -
params
object Hide params attribute Show params attribute object
-
*
string Additional properties
-
-
path
string -
port
number -
proxy
object -
read_timeout
string A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
scheme
string Values are
http
orhttps
. -
url
string
-
-
response_content_type
string Values are
json
,yaml
, ortext
.
-
-
search
object Hide search attributes Show search attributes object
-
extract
array[string] -
request
object Required Hide request attributes Show request attributes object
-
body
object Hide body attribute Show body attribute object
-
query
object Required An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
External documentation
-
-
indices
array[string] -
indices_options
object Hide indices_options attributes Show indices_options attributes object
-
allow_no_indices
boolean If false, the request returns an error if any wildcard expression, index alias, or
_all
value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targetingfoo*,bar*
returns an error if an index starts withfoo
but no index starts withbar
. -
expand_wildcards
string | array[string] -
ignore_unavailable
boolean If true, missing or closed indices are not included in the response.
-
ignore_throttled
boolean If true, concrete, expanded or aliased indices are ignored when frozen.
-
-
search_type
string Values are
query_then_fetch
ordfs_query_then_fetch
. -
template
object Hide template attributes Show template attributes object
-
explain
boolean -
id
string -
params
object Hide params attribute Show params attribute object
-
*
object Additional properties
-
-
profile
boolean -
source
string An inline search template. Supports the same parameters as the search API's request body. Also supports Mustache variables. If no id is specified, this parameter is required.
-
-
rest_total_hits_as_int
boolean
-
-
timeout
string A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
-
-
simple
object Hide simple attribute Show simple attribute object
-
*
object Additional properties
-
-
-
metadata
object Hide metadata attribute Show metadata attribute object
-
*
object Additional properties
-
-
throttle_period
string A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value. -
throttle_period_in_millis
number Time unit for milliseconds
-
transform
object Hide transform attributes Show transform attributes object
-
chain
array[object] -
script
object Hide script attributes Show script attributes object
-
search
object Hide search attributes Show search attributes object
-
request
object Required Hide request attributes Show request attributes object
-
body
object Hide body attribute Show body attribute object
-
query
object Required An Elasticsearch Query DSL (Domain Specific Language) object that defines a query.
External documentation
-
-
indices
array[string] -
indices_options
object Hide indices_options attributes Show indices_options attributes object
-
allow_no_indices
boolean If false, the request returns an error if any wildcard expression, index alias, or
_all
value targets only missing or closed indices. This behavior applies even if the request targets other open indices. For example, a request targetingfoo*,bar*
returns an error if an index starts withfoo
but no index starts withbar
. -
expand_wildcards
string | array[string] -
ignore_unavailable
boolean If true, missing or closed indices are not included in the response.
-
ignore_throttled
boolean If true, concrete, expanded or aliased indices are ignored when frozen.
-
-
search_type
string Values are
query_then_fetch
ordfs_query_then_fetch
. -
template
object Hide template attributes Show template attributes object
-
explain
boolean -
id
string -
params
object Hide params attribute Show params attribute object
-
*
object Additional properties
-
-
profile
boolean -
source
string An inline search template. Supports the same parameters as the search API's request body. Also supports Mustache variables. If no id is specified, this parameter is required.
-
-
rest_total_hits_as_int
boolean
-
-
timeout
string Required A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
-
-
-
trigger
object Hide trigger attribute Show trigger attribute object
-
schedule
object Hide schedule attributes Show schedule attributes object
-
timezone
string -
cron
string -
daily
object Hide daily attribute Show daily attribute object
-
hourly
object Hide hourly attribute Show hourly attribute object
-
minute
array[number] Required
-
-
interval
string A duration. Units can be
nanos
,micros
,ms
(milliseconds),s
(seconds),m
(minutes),h
(hours) andd
(days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
-
-
curl \
--request PUT 'http://api.example.com/_watcher/watch/{id}' \
--header "Authorization: $API_KEY" \
--header "Content-Type: application/json" \
--data '"{\n \"trigger\" : {\n \"schedule\" : { \"cron\" : \"0 0/1 * * * ?\" }\n },\n \"input\" : {\n \"search\" : {\n \"request\" : {\n \"indices\" : [\n \"logstash*\"\n ],\n \"body\" : {\n \"query\" : {\n \"bool\" : {\n \"must\" : {\n \"match\": {\n \"response\": 404\n }\n },\n \"filter\" : {\n \"range\": {\n \"@timestamp\": {\n \"from\": \"{{ctx.trigger.scheduled_time}}||-5m\",\n \"to\": \"{{ctx.trigger.triggered_time}}\"\n }\n }\n }\n }\n }\n }\n }\n }\n },\n \"condition\" : {\n \"compare\" : { \"ctx.payload.hits.total\" : { \"gt\" : 0 }}\n },\n \"actions\" : {\n \"email_admin\" : {\n \"email\" : {\n \"to\" : \"admin@domain.host.com\",\n \"subject\" : \"404 recently encountered\"\n }\n }\n }\n}"'
{
"trigger" : {
"schedule" : { "cron" : "0 0/1 * * * ?" }
},
"input" : {
"search" : {
"request" : {
"indices" : [
"logstash*"
],
"body" : {
"query" : {
"bool" : {
"must" : {
"match": {
"response": 404
}
},
"filter" : {
"range": {
"@timestamp": {
"from": "{{ctx.trigger.scheduled_time}}||-5m",
"to": "{{ctx.trigger.triggered_time}}"
}
}
}
}
}
}
}
}
},
"condition" : {
"compare" : { "ctx.payload.hits.total" : { "gt" : 0 }}
},
"actions" : {
"email_admin" : {
"email" : {
"to" : "admin@domain.host.com",
"subject" : "404 recently encountered"
}
}
}
}
{
"created": true,
"_id": "string",
"_primary_term": 42.0,
"_seq_no": 42.0,
"_version": 42.0
}