Path parameters

  • idstring Required

    The identifier for the watch.

Query parameters

  • activeboolean

    The initial state of the watch. The default value is true, which means the watch is active by default.

  • only update the watch if the last operation that has changed the watch has the specified primary term

  • if_seq_nonumber

    only update the watch if the last operation that has changed the watch has the specified sequence number

  • versionnumber

    Explicit version number for concurrency control

application/json

Body

  • actionsobject

    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
      • Values are email, webhook, index, logging, slack, or pagerduty.

      • conditionobject
        Hide condition attributes Show condition attributes object
        • alwaysobject
        • Hide array_compare attribute Show array_compare attribute object
          • *object Additional properties
            Hide * attribute Show * attribute object
        • compareobject
          Hide compare attribute Show compare attribute object
          • *object Additional properties
        • neverobject
        • scriptobject
          Hide script attributes Show script attributes object
          • langstring

            Any of:

            Values are painless, expression, mustache, or java.

          • paramsobject
            Hide params attribute Show params attribute object
            • *object Additional properties
          • sourcestring | object

            One of:
          • idstring
      • foreachstring
      • namestring
      • A duration. Units can be nanos, micros, ms (milliseconds), s (seconds), m (minutes), h (hours) and d (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.

      • Time unit for milliseconds

      • transformobject
        Hide transform attributes Show transform attributes object
        • chainarray[object]
        • scriptobject
          Hide script attributes Show script attributes object
          • langstring
          • paramsobject
            Hide params attribute Show params attribute object
            • *object Additional properties
          • sourcestring | object

            One of:
          • idstring
      • indexobject
        Hide index attributes Show index attributes object
        • indexstring Required
        • doc_idstring
        • refreshstring

          Values are true, false, or wait_for.

        • op_typestring

          Values are index or create.

        • timeoutstring

          A duration. Units can be nanos, micros, ms (milliseconds), s (seconds), m (minutes), h (hours) and d (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.

        • Path to field or array of paths. Some API's support wildcards in the path to select multiple fields.

      • loggingobject
        Hide logging attributes Show logging attributes object
      • emailobject
        Hide email attributes Show email attributes object
      • pagerdutyobject
        Hide pagerduty attributes Show pagerduty attributes object
      • slackobject
        Hide slack attributes Show slack attributes object
      • webhookobject
        Hide webhook attributes Show webhook attributes object
        • authobject
          Hide auth attribute Show auth attribute object
          • basicobject Required
            Hide basic attributes Show basic attributes object
        • bodystring
        • A duration. Units can be nanos, micros, ms (milliseconds), s (seconds), m (minutes), h (hours) and d (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.

        • headersobject
          Hide headers attribute Show headers attribute object
        • hoststring
        • methodstring

          Values are head, get, post, put, or delete.

        • paramsobject
          Hide params attribute Show params attribute object
          • *string Additional properties
        • pathstring
        • portnumber
        • proxyobject
          Hide proxy attributes Show proxy attributes object
        • A duration. Units can be nanos, micros, ms (milliseconds), s (seconds), m (minutes), h (hours) and d (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.

        • schemestring

          Values are http or https.

        • urlstring
  • conditionobject
    Hide condition attributes Show condition attributes object
    • alwaysobject
    • Hide array_compare attribute Show array_compare attribute object
      • *object Additional properties
        Hide * attribute Show * attribute object
    • compareobject
      Hide compare attribute Show compare attribute object
      • *object Additional properties
    • neverobject
    • scriptobject
      Hide script attributes Show script attributes object
      • langstring

        Any of:

        Values are painless, expression, mustache, or java.

      • paramsobject
        Hide params attribute Show params attribute object
        • *object Additional properties
      • sourcestring | object

        One of:
      • idstring
  • inputobject
    Hide input attributes Show input attributes object
    • chainobject
      Hide chain attribute Show chain attribute object
      • inputsarray[object] Required
        Hide inputs attribute Show inputs attribute object
        • *object
    • httpobject
      Hide http attributes Show http attributes object
      • extractarray[string]
      • requestobject
        Hide request attributes Show request attributes object
        • authobject
          Hide auth attribute Show auth attribute object
          • basicobject Required
            Hide basic attributes Show basic attributes object
        • bodystring
        • A duration. Units can be nanos, micros, ms (milliseconds), s (seconds), m (minutes), h (hours) and d (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.

        • headersobject
          Hide headers attribute Show headers attribute object
        • hoststring
        • methodstring

          Values are head, get, post, put, or delete.

        • paramsobject
          Hide params attribute Show params attribute object
          • *string Additional properties
        • pathstring
        • portnumber
        • proxyobject
          Hide proxy attributes Show proxy attributes object
        • A duration. Units can be nanos, micros, ms (milliseconds), s (seconds), m (minutes), h (hours) and d (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.

        • schemestring

          Values are http or https.

        • urlstring
      • Values are json, yaml, or text.

    • simpleobject
      Hide simple attribute Show simple attribute object
      • *object Additional properties
  • metadataobject
    Hide metadata attribute Show metadata attribute object
  • A duration. Units can be nanos, micros, ms (milliseconds), s (seconds), m (minutes), h (hours) and d (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.

  • Time unit for milliseconds

  • transformobject
    Hide transform attributes Show transform attributes object
    • chainarray[object]
    • scriptobject
      Hide script attributes Show script attributes object
      • langstring
      • paramsobject
        Hide params attribute Show params attribute object
        • *object Additional properties
      • sourcestring | object

        One of:
      • idstring
  • triggerobject
    Hide trigger attribute Show trigger attribute object
    • scheduleobject
      Hide schedule attributes Show schedule attributes object
      • timezonestring
      • cronstring
      • dailyobject
        Hide daily attribute Show daily attribute object
        • atarray[string | object] Required

          A time of day, expressed either as hh:mm, noon, midnight, or an hour/minutes structure.

          A time of day, expressed either as hh:mm, noon, midnight, or an hour/minutes structure.

          One of:
      • hourlyobject
        Hide hourly attribute Show hourly attribute object
      • intervalstring

        A duration. Units can be nanos, micros, ms (milliseconds), s (seconds), m (minutes), h (hours) and d (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.

      • monthlyobject | array[object]

        One of:
        Hide attributes Show attributes object
        • atarray[string] Required
        • onarray[number] Required
      • weeklyobject | array[object]

        One of:
        Hide attributes Show attributes object
        • atarray[string] Required
        • onarray[string] Required

          Values are sunday, monday, tuesday, wednesday, thursday, friday, or saturday.

      • yearlyobject | array[object]

        One of:
        Hide attributes Show attributes object
        • atarray[string] Required
        • intarray[string] Required

          Values are january, february, march, april, may, june, july, august, september, october, november, or december.

        • onarray[number] Required

Responses

POST /_watcher/watch/{id}
PUT _watcher/watch/my-watch
{
  "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" : "[email protected]",
        "subject" : "404 recently encountered"
      }
    }
  }
}
resp = client.watcher.put_watch(
    id="my-watch",
    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": "[email protected]",
                "subject": "404 recently encountered"
            }
        }
    },
)
const response = await client.watcher.putWatch({
  id: "my-watch",
  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: "[email protected]",
        subject: "404 recently encountered",
      },
    },
  },
});
response = client.watcher.put_watch(
  id: "my-watch",
  body: {
    "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": "[email protected]",
          "subject": "404 recently encountered"
        }
      }
    }
  }
)
$resp = $client->watcher()->putWatch([
    "id" => "my-watch",
    "body" => [
        "trigger" => [
            "schedule" => [
                "cron" => "0 0/1 * * * ?",
            ],
        ],
        "input" => [
            "search" => [
                "request" => [
                    "indices" => array(
                        "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" => "[email protected]",
                    "subject" => "404 recently encountered",
                ],
            ],
        ],
    ],
]);
curl -X PUT -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"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":"[email protected]","subject":"404 recently encountered"}}}}' "$ELASTICSEARCH_URL/_watcher/watch/my-watch"
Request example
Run `PUT _watcher/watch/my-watch` add a watch. The watch schedule triggers every minute. The watch search input looks for any 404 HTTP responses that occurred in the last five minutes. The watch condition checks if any search hits where found. When found, the watch action sends an email to an administrator.
{
  "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" : "[email protected]",
        "subject" : "404 recently encountered"
      }
    }
  }
}