Spaces method and path for this operation:
Refer to Spaces for more information.
Creates a rule with the given identifier, or fully replaces it if one already exists.
[Required authorization] Route required privileges: manage_alerting-v2-rules.
Body
-
Artifacts attached to the rule, each shaped as
{ id, type, data }.datais a type-specific object (for example arunbookmay carrycontent, adashboardmay carrydashboardId). Per-type shape is validated by the artifact-type registry when the type is registered; unregistered types pass through with envelope bounds only.Not more than
100elements. -
Grouping configuration.
Additional properties are NOT allowed.
kind
string Required The kind of the rule.
Any of: Default. Tracks each problem as an alert episode and its lifecycle, link it to workflows to notify your team. Use when the user wants to detect and respond.
Value is
alert.Matches are stored as queryable events. No alerts, no notifications - just data. Use when the user wants to collect evidence.
Value is
signal.-
Rule metadata.
Additional properties are NOT allowed.
no_data_strategy
string How to handle no-data situations. "last_known_status" holds the last known status; "recover" forces recovery; "none" disables no-data detection. "emit" is not currently accepted by the create/update API. Standalone-format rules must provide a
no_dataquery block when this is not "none"; composed-format rules usebaseas the data-presence query.Any of: Holds the last known episode status when no data is present.
Value is
last_known_status.Emits a
no_dataalert event when no_data query returns no rows for the group. "emit" is not currently accepted by the create/update API.Value is
emit.Resolves the alert episode to inactive on the first no-data run.
Value is
recover.No-data situations are ignored (default).
Value is
none.recovery_strategy
string How recovery is detected. "no_breach" recovers groups that stop breaching; "query" uses a custom recovery query; "none" disables recovery.
-
Execution schedule configuration.
Additional properties are NOT allowed.
-
Episode state transition thresholds (alert-only).
Additional properties are NOT allowed.
-
Time field used for the lookback window range filter.
Minimum length is
1, maximum length is128. Default value is@timestamp.
Responses
-
Returns the replaced rule.
-
Returns the newly created rule.
-
Indicates an invalid schema or parameters.
-
Indicates the request was not authenticated.
-
Indicates the user does not have the required privileges to perform the request.
-
Indicates a rule with the given ID does not exist.
-
Indicates the rule was created or updated concurrently, or the request changes immutable fields.
-
Indicates an unexpected server-side error.
-
Indicates the alerting engine is disabled by the
alerting:v2:enabledadvanced setting.
curl \
--request PUT 'https://localhost:5601/api/alerting/v2/rules/{id}' \
--header "Authorization: $API_KEY" \
--header "Content-Type: application/json" \
--header "kbn-xsrf: true" \
--data '"{\n \"grouping\": {\n \"fields\": [\n \"host.name\"\n ]\n },\n \"kind\": \"alert\",\n \"metadata\": {\n \"description\": \"Alerts when average CPU usage exceeds a threshold.\",\n \"name\": \"Host CPU high\",\n \"tags\": [\n \"production\",\n \"infra\"\n ]\n },\n \"query\": {\n \"breach\": {\n \"query\": \"FROM metrics-* | WHERE host.cpu.usage \u003e 0.9 | STATS avg_cpu = AVG(host.cpu.usage) BY host.name\"\n },\n \"format\": \"standalone\"\n },\n \"recovery_strategy\": \"no_breach\",\n \"schedule\": {\n \"every\": \"1m\",\n \"lookback\": \"5m\"\n },\n \"state_transition\": {\n \"pending_count\": 1,\n \"recovering_count\": 1\n },\n \"time_field\": \"@timestamp\"\n}"'
{
"grouping": {
"fields": [
"host.name"
]
},
"kind": "alert",
"metadata": {
"description": "Alerts when average CPU usage exceeds a threshold.",
"name": "Host CPU high",
"tags": [
"production",
"infra"
]
},
"query": {
"breach": {
"query": "FROM metrics-* | WHERE host.cpu.usage > 0.9 | STATS avg_cpu = AVG(host.cpu.usage) BY host.name"
},
"format": "standalone"
},
"recovery_strategy": "no_breach",
"schedule": {
"every": "1m",
"lookback": "5m"
},
"state_transition": {
"pending_count": 1,
"recovering_count": 1
},
"time_field": "@timestamp"
}
{
"created_at": "2026-01-15T12:00:00.000Z",
"created_by": "elastic",
"enabled": true,
"grouping": {
"fields": [
"host.name"
]
},
"id": "rule-1",
"kind": "alert",
"metadata": {
"description": "Alerts when average CPU usage exceeds a threshold.",
"name": "Host CPU high",
"tags": [
"production",
"infra"
],
"version": 1
},
"query": {
"breach": {
"query": "FROM metrics-* | WHERE host.cpu.usage > 0.9 | STATS avg_cpu = AVG(host.cpu.usage) BY host.name"
},
"format": "standalone"
},
"recovery_strategy": "no_breach",
"schedule": {
"every": "1m",
"lookback": "5m"
},
"state_transition": {
"pending_count": 1,
"recovering_count": 1
},
"time_field": "@timestamp",
"updated_at": "2026-01-15T12:00:00.000Z",
"updated_by": "elastic",
"version": "WzAsMV0="
}
{
"created_at": "2026-01-15T12:00:00.000Z",
"created_by": "elastic",
"enabled": true,
"grouping": {
"fields": [
"host.name"
]
},
"id": "rule-1",
"kind": "alert",
"metadata": {
"description": "Alerts when average CPU usage exceeds a threshold.",
"name": "Host CPU high",
"tags": [
"production",
"infra"
],
"version": 1
},
"query": {
"breach": {
"query": "FROM metrics-* | WHERE host.cpu.usage > 0.9 | STATS avg_cpu = AVG(host.cpu.usage) BY host.name"
},
"format": "standalone"
},
"recovery_strategy": "no_breach",
"schedule": {
"every": "1m",
"lookback": "5m"
},
"state_transition": {
"pending_count": 1,
"recovering_count": 1
},
"time_field": "@timestamp",
"updated_at": "2026-01-15T12:00:00.000Z",
"updated_by": "elastic",
"version": "WzAsMV0="
}
{
"code": "BAD_REQUEST",
"details": {
"errors": {
"metadata": [
"Required"
]
}
},
"error": "Bad Request",
"message": "metadata: Required"
}
{
"code": "UNAUTHORIZED",
"error": "Unauthorized",
"message": "Authentication required to access this API."
}
{
"code": "FORBIDDEN",
"error": "Forbidden",
"message": "The current user does not have the required privileges for this request."
}
{
"code": "RULE_NOT_FOUND",
"details": {
"rule_id": "rule-1"
},
"error": "Not Found",
"message": "Rule with id \"rule-1\" not found"
}
{
"code": "RULE_VERSION_CONFLICT",
"details": {
"rule_id": "rule-1"
},
"error": "Conflict",
"message": "Rule with id \"rule-1\" has already been updated by another user"
}
{
"code": "INTERNAL_SERVER_ERROR",
"error": "Internal Server Error",
"message": "An unexpected error occurred."
}
{
"code": "ALERTING_DISABLED",
"error": "Service Unavailable",
"message": "Alerting is disabled."
}