Create a rule
- Base URL
-
https://{kibana_url}
- POST /api/alerting/v2/rules
- POST /s/{space_id}/api/alerting/v2/rules
Creates a rule with a server-generated identifier. To create or replace a rule with a client-supplied identifier, use PUT /api/alerting/v2/rules/{id}/.
Required privileges
- Privileges manage_alerting-v2-rules
Path parameters
-
space_idstringoptional -
An identifier for the space. If
space_idis not provided in the URL, the default space is used. Refer to Spaces for more information.
Request body
-
artifactsobject[] · min items: 1 · max items: 100 -
Optional objects attached to the rule, such as a runbook or a dashboard. Each item has
id,type, anddata. The shape ofdatadepends ontype. For example, arunbookusescontentand adashboardusesdashboard_id. Known types are validated against that shape. Unknown types are stored whenid,type, anddataare present. An empty array is rejected: omitartifactson create, or sendnullon PATCH to clear. -
kindenumrequired -
Whether the rule creates alerts (
alert) or only stores matching events (signal). -
Values:
alertsignal -
metadataobjectrequired -
Rule metadata.
-
builderobject -
Identifies the rule builder that authored this rule (e.g. "threshold"). Absent for rules authored directly in ES|QL; send
nullon PATCH to clear it. -
descriptionstring · min length: 1 · max length: 1024 -
Human-readable description of the rule. Omit to leave it unset; send
nullon PATCH to clear it. An empty string is rejected. -
no_dataunion oneOf -
What the rule does when a group has no data. Required when
kindisalert. Not allowed whenkindissignal. Any strategy other thanignorerequires eitherquery.breachorno_data.query, so that a group with no data can be told apart from one that stopped breaching. -
One of:
(determined by
strategy) -
queryobjectrequired -
ES|QL query the rule evaluates.
baseis required.breachis an optional clause appended to it. -
recoveryunion oneOf -
When an alert recovers. Required when
kindisalert. Not allowed whenkindissignal. -
One of:
(determined by
strategy) -
state_transitionobject -
Specifies how many consecutive matches, or how long a condition must hold, before an alert becomes
activeorinactive. Allowed only whenkindisalert. -
pendingobject -
recoveringobject
strategy: ignore
Does not check whether a group still has data. Missing groups do not produce no_data events.
strategy: keep_last
Holds the alert's current status when the rule finds no data.
strategy: resolve
Closes the alert the first time the rule finds no data for a group.
strategy: alert
Marks an existing alert active when the rule finds no data. It never opens an alert for a group that has not breached. Not accepted when creating or updating rules.
strategy: no_breach
Recovers the alert when its group no longer appears in the breach results.
strategy: condition
Recovers the alert when query.base plus segment returns the group. Requires query.breach.
strategy: query
Recovers the alert when this separate query returns the group.
Responses
Returns the newly created rule.
-
artifactsobject[] · min items: 1 · max items: 100 -
Optional objects attached to the rule, such as a runbook or a dashboard. Each item has
id,type, anddata. The shape ofdatadepends ontype. For example, arunbookusescontentand adashboardusesdashboard_id. Known types are validated against that shape. Unknown types are stored whenid,type, anddataare present. An empty array is rejected: omitartifactson create, or sendnullon PATCH to clear. -
created_atstring · format: date-time · max length: 64required -
ISO timestamp when the rule was created.
-
kindenumrequired -
Whether the rule creates alerts (
alert) or only stores matching events (signal). -
Values:
alertsignal -
metadataobjectrequired -
Rule metadata.
-
builderobject -
Identifies the rule builder that authored this rule (e.g. "threshold"). Absent for rules authored directly in ES|QL; send
nullon PATCH to clear it. -
descriptionstring · min length: 1 · max length: 1024 -
Human-readable description of the rule. Omit to leave it unset; send
nullon PATCH to clear it. An empty string is rejected. -
no_dataunion oneOf -
What the rule does when a group has no data. Required when
kindisalert. Not allowed whenkindissignal. Any strategy other thanignorerequires eitherquery.breachorno_data.query, so that a group with no data can be told apart from one that stopped breaching. -
One of:
(determined by
strategy) -
queryobjectrequired -
ES|QL query the rule evaluates.
baseis required.breachis an optional clause appended to it. -
recoveryunion oneOf -
When an alert recovers. Required when
kindisalert. Not allowed whenkindissignal. -
One of:
(determined by
strategy) -
state_transitionobject -
Specifies how many consecutive matches, or how long a condition must hold, before an alert becomes
activeorinactive. Allowed only whenkindisalert. -
pendingobject -
recoveringobject -
time_fieldstring · min length: 1 · max length: 256 · default: @timestamp -
Document field Kibana uses with
schedule.lookbackto time-filterquery.base. -
updated_atstring · format: date-time · max length: 64required -
ISO timestamp when the rule was last updated.
strategy: ignore
Does not check whether a group still has data. Missing groups do not produce no_data events.
strategy: keep_last
Holds the alert's current status when the rule finds no data.
strategy: resolve
Closes the alert the first time the rule finds no data for a group.
strategy: alert
Marks an existing alert active when the rule finds no data. It never opens an alert for a group that has not breached. Not accepted when creating or updating rules.
strategy: no_breach
Recovers the alert when its group no longer appears in the breach results.
strategy: condition
Recovers the alert when query.base plus segment returns the group. Requires query.breach.
strategy: query
Recovers the alert when this separate query returns the group.
Indicates an invalid schema or parameters.
-
codestringrequired -
Stable error code you can branch on, for example
INVALID_SCHEDULEorRULE_ALREADY_EXISTS. -
detailsmap string to object -
Optional structured context whose keys depend on
code. Identifier keys such asrule_id,action_policy_idandgroup_hashare stable, permanent public identifiers. On a 400 request-validation error,details.source(params,query, orbody) names the failing part and is the only guaranteed key. The siblingdetails.errorsmay change. Do not branch on it.
Indicates the request was not authenticated.
-
codestringrequired -
Stable error code you can branch on, for example
INVALID_SCHEDULEorRULE_ALREADY_EXISTS. -
detailsmap string to object -
Optional structured context whose keys depend on
code. Identifier keys such asrule_id,action_policy_idandgroup_hashare stable, permanent public identifiers. On a 400 request-validation error,details.source(params,query, orbody) names the failing part and is the only guaranteed key. The siblingdetails.errorsmay change. Do not branch on it.
Indicates the user does not have the required privileges to perform the request.
-
codestringrequired -
Stable error code you can branch on, for example
INVALID_SCHEDULEorRULE_ALREADY_EXISTS. -
detailsmap string to object -
Optional structured context whose keys depend on
code. Identifier keys such asrule_id,action_policy_idandgroup_hashare stable, permanent public identifiers. On a 400 request-validation error,details.source(params,query, orbody) names the failing part and is the only guaranteed key. The siblingdetails.errorsmay change. Do not branch on it.
Indicates an unexpected server-side error.
-
codestringrequired -
Stable error code you can branch on, for example
INVALID_SCHEDULEorRULE_ALREADY_EXISTS. -
detailsmap string to object -
Optional structured context whose keys depend on
code. Identifier keys such asrule_id,action_policy_idandgroup_hashare stable, permanent public identifiers. On a 400 request-validation error,details.source(params,query, orbody) names the failing part and is the only guaranteed key. The siblingdetails.errorsmay change. Do not branch on it.
Indicates the alerting engine is disabled by the alerting:v2:enabled advanced setting.
-
codestringrequired -
Stable error code you can branch on, for example
INVALID_SCHEDULEorRULE_ALREADY_EXISTS. -
detailsmap string to object -
Optional structured context whose keys depend on
code. Identifier keys such asrule_id,action_policy_idandgroup_hashare stable, permanent public identifiers. On a 400 request-validation error,details.source(params,query, orbody) names the failing part and is the only guaranteed key. The siblingdetails.errorsmay change. Do not branch on it.