Kibana: Rules & Stack Rule Types
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Checked on 2026-11-09 against Kibana 9.5.x. Tested with Elasticsearch 9.5.6 and Kibana 9.5.6 in the hands-on lab (trial licence): the Elasticsearch query rule of the error-log spike fired and reached the receiver after the lab’s load generator logged errors.
To do this by hand, follow Create a Rule with a Connector.
A rule is the unit of alerting in Kibana: a saved object that says what to check, how often, and what to do when the check succeeds. This page covers the generic life cycle of a rule (create, tune, enable, snooze, export, automate) and then the Stack rule types, the four that are not tied to a Kibana solution and appear under Stack Management: the Elasticsearch query rule, the index threshold rule, tracking containment and the transform health rule. The rule types of Observability (custom threshold, inventory, log threshold, APM, SLO burn rate, degraded docs) are on Observability Rules, and the model they all share is on Alerting Overview.
Creating and managing rules
Open Stack Management, Alerts and insights, Rules (or search for it). Since 9.4 the Manage rules links of Observability, Discover and Stack Monitoring open the same page, so this is the one place to manage every rule type.
-
Choose Create rule. A flyout opens; some apps preselect the rule type.
-
Define the conditions. Rule types differ, but many use a clause-based expression, for example an index, a query and a threshold on a count or a numeric aggregation.
-
Set the check interval, how often the conditions are evaluated. Checks are queued and run as close to the interval as capacity allows, so treat it as approximate.
-
Optionally tune alert flapping detection, which is on by default: a look-back window and a status-change threshold, for example six status changes in the last ten runs marks an alert as flapping. Per-rule settings are generally available on the Stack since 9.3; on 9.0 to 9.2 only the global settings exist (in the Rules page Settings).
-
Add actions: a connector, a frequency and the message. A custom interval cannot be shorter than the check interval, and per-alert actions need an action group in Run when (for example
Query matchedorRecovered). Actions are the subject of Actions, Frequency & Action Variables; the add rule variable button inserts the variables of the rule type. -
In the details step give the rule a name and tags. Tags do not route notifications; they make the Rules list filterable and the Alerts panel of a dashboard selectable, so the Bookshelf rules all carry the tag
bookshelf.
Source: Create and manage rules.
Settings every rule type shares
Besides the conditions, three settings recur on every Stack rule page and decide how noisy a rule is.
| Setting | Effect |
|---|---|
Check interval |
How often the rule runs. Set it lower than the time window so that no period falls between two runs; the documentation repeats this for the Elasticsearch query, index threshold and other rule types. |
Consecutive runs (advanced option) |
How many consecutive runs must meet the condition before an alert occurs. The default is |
Scope (Elasticsearch query rule) |
Which Kibana feature privileges can see the rule and its alerts: All (the default since 9.3, any of Infrastructure, Logs, APM, Synthetics or Stack rules), Logs, Metrics or Stack Management. It is a visibility setting and does not change what the rule queries. |
Operating a rule
From the rule list or the action menu of a rule:
-
Edit rule reopens the flyout. Clone, Run rule (run now without waiting for the next check) and Update API key are in the same menu according to the Observability documentation.
-
Enable and disable with the status dropdown. Disable rules you do not need: a disabled rule stops its checks and reduces the load on the cluster.
-
Snooze keeps the rule running on schedule but generates no actions; it can be set for a period, indefinitely or with single or recurring downtimes, and cancelled or shortened later. For temporary silence across many rules use a maintenance window (see Alert Lifecycle, Snooze & Maintenance Windows).
-
Click the rule name for the rule details: every alert with name, status, detection time and duration. The Last response column of the list shows whether the last run
succeeded, ended with awarning(some non-critical errors) orfailed. The History tab lists failed actions, and the Errored Actions panel opens from the message icon or the errored actions count. -
Rules are saved objects, so Saved Objects exports and imports them. Exported rules are disabled; after a successful import Kibana prompts you to re-enable them, which also creates a fresh API key. Stack Monitoring rules are created automatically and cannot be managed in Saved Objects, and Security rules use the Security UI.
Rules run in the background with an API key that captures the privileges of the user who last saved them, so a rule whose editor lacks index privileges on the queried data starts failing; Update API key re-binds it to the current user. The privilege matrix and the key life cycle are on Spaces, Roles & Privileges and Alerting Setup, Security & Scaling.
Rules as code
Everything the flyout does is available over the REST API, which is how rules belong in version control. A rule is a JSON document
with the same parts as in the UI: name, rule_type_id, consumer (the feature that owns it), schedule.interval, params (the
conditions, different per rule type), actions, tags, and optionally alert_delay, flapping and enabled. Each action has the
connector id, the group, the params of the connector (a Mustache template) and a frequency object (summary, notify_when
and throttle). The id in the URL is optional; give one to make the rule addressable and to make a script idempotent.
Rule types and their action groups are discoverable instead of memorised: GET /s/bookshelf/api/alerting/rule_types returns, for
each type, its id, action_groups and the variables it provides. The examples below use the space bookshelf and the elastic
user of the lab for brevity; in a real installation use a service user, because that user’s privileges become the rule’s API key.
The lab Kibana connector for the webhook receiver is created once (the connectors page covers authentication and the other types):
export KIBANA_URL=http://localhost:5601
curl -s -u elastic:"$ELASTIC_PASSWORD" -X POST "$KIBANA_URL/s/bookshelf/api/actions/connector/bookshelf-webhook" \
-H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d '{
"name": "bookshelf-webhook",
"connector_type_id": ".webhook",
"config": { "method": "post", "url": "http://webhook-receiver:8080/kibana", "hasAuth": false },
"secrets": {}
}'
Reference: Create a connector and
Create a rule. A Kibana running in a container
can reach webhook-receiver by its Compose service name; if xpack.actions.allowedHosts is configured the host must be added to it.
The Terraform equivalent (elasticstack_kibana_alerting_rule) and the rest of the API are on
Alerting APIs & Terraform.
The Stack rule types
Rule type and rule_type_id |
Detects | Label on the rule type catalogue |
|---|---|---|
Elasticsearch query ( |
A user-defined query whose match count meets a threshold, in Query DSL, KQL, Lucene or ES|QL |
Not labelled (Serverless: generally available) |
Index threshold ( |
An aggregation of a field over documents that meets a threshold, optionally per group |
Generally available on Serverless and on the Stack |
Tracking containment ( |
An entity entering or leaving a boundary |
Generally available on Serverless and on the Stack |
Transform health ( |
A continuous transform that is not started or is unhealthy |
Beta in the catalogue; the transform page itself marks it generally available |
Source: Rule types. Machine learning rules (anomaly detection and job health) are labelled beta in the catalogue and are covered on Machine Learning & AIOps; Security rules are managed in the Security app; Stack Monitoring rules are on Stack Monitoring & AutoOps.
The Elasticsearch query rule
The Elasticsearch query rule runs a query on every check, compares the match count (or an aggregate of it) with a threshold and schedules actions when the condition holds. It is the most general Stack rule and the first one to reach for when no Observability rule fits.
Query types. Four are offered:
-
Query DSL: pick an index and a time field and write the query body. Only
query,fields,_sourceandruntime_mappingsare used; other DSL fields are ignored. -
KQL or Lucene: pick a data view and type a text query such as
http.request.referrer: "https://example.com". -
ES|QL: write a source command followed by optional processing commands separated by pipes (available from 8.16). The rule matches when the query returns rows. Pick the time field (for example
@timestamp) that filters rows by the rule’s time window (from 9.2 on the Stack). Create an alert if matches are found produces one alert for all rows; Create an alert for each row produces one alert per row, with a unique id where possible.
Conditions for DSL, KQL and Lucene. When is the aggregation (count, average, sum, min, max; count needs no field),
Over aggregates all documents or Grouped Over groups by up to four fields with a terms or multi-terms aggregation (one alert per
distinct value set; only the top groups are checked, which limits alerts on high-cardinality fields, and the number of groups is a
required setting). The threshold operators are is above, is above or equals, is below, is below or equals, is between
(both bounds inclusive) and is not between (both bounds exclusive). Number of documents to send is how many matching
documents are passed to the actions. The time window is how far back the query looks; keep the check interval smaller than it.
Exclude matches from previous run is on by default and is the setting that most often explains "why did it not fire again". The rule remembers the timestamp of the latest match and counts only documents newer than it. The documentation’s example uses a one-hour window, a one-minute check and a threshold of more than 99 matches:
| Run | Matches in the window | Already counted | New matches | Result |
|---|---|---|---|---|
1 |
113 |
0 |
113 |
Alert |
2 |
127 |
105 |
22 |
No alert |
3 |
159 |
88 |
71 |
No alert |
4 |
190 |
71 |
119 |
Alert |
The option is unavailable when a grouping field is used, and it is the right choice for rules that count events (errors) and the wrong one for rules that watch a state that stays true (a gauge); for the latter switch it off.
ES|QL time zone. Date functions such as DATE_EXTRACT use UTC by default. Put SET time_zone="Asia/Tokyo"; at the start of the query
to change that (from 9.4 on the Stack); the resolution order is the SET statement, then the esql.query.settings.time_zone cluster
setting (planned on the Stack), then UTC, and the Dashboards time zone setting does not apply to rules.
Test query shows the number of matching documents (DSL, KQL, Lucene) or a result table (ES|QL) and reports invalid queries.
Action groups and variables. The groups are Query matched (the threshold is met) and Recovered (it no longer is). Rule-specific variables:
| Variable | Content |
|---|---|
|
Description of the condition, for example "Query matched documents" |
|
ISO timestamp when the condition was met |
|
Array of the most recent matching documents; each has |
|
URL of the rule that generated the alert |
|
Preconstructed message and title |
|
The number that met the threshold |
|
Rule parameters such as |
|
Source field values, if configured to be copied into alerts |
Source: Elasticsearch query rule.
Bookshelf example: the error-log spike. The lab alert "more than 20 ERROR log lines in 5 minutes" is a count over the logs data
view with a KQL filter. The data view bookshelf-logs (created on
Data Views & Discover) points at logs-*.otel-*; use the field
that Discover shows for the log level: severity_text in the lab, whose logs arrive over OTLP (log.level in ECS-shaped logs).
curl -s -u elastic:"$ELASTIC_PASSWORD" -X POST "$KIBANA_URL/s/bookshelf/api/alerting/rule/bookshelf-error-log-spike" \
-H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d '{
"name": "Bookshelf error-log spike",
"rule_type_id": ".es-query",
"consumer": "stackAlerts",
"tags": ["bookshelf", "bookshelf-sre"],
"schedule": { "interval": "1m" },
"params": {
"searchType": "searchSource",
"searchConfiguration": {
"index": "bookshelf-logs",
"query": { "language": "kuery", "query": "severity_text: \"ERROR\"" }
},
"aggType": "count",
"groupBy": "all",
"excludeHitsFromPreviousRun": false,
"size": 10,
"threshold": [20],
"thresholdComparator": ">",
"timeWindowSize": 5,
"timeWindowUnit": "m"
},
"actions": [
{
"id": "bookshelf-webhook",
"group": "query matched",
"frequency": { "summary": false, "notify_when": "onActionGroupChange", "throttle": null },
"params": {
"body": "{\"rule\":\"{{rule.name}}\",\"value\":\"{{context.value}}\",\"conditions\":\"{{context.conditions}}\",\"link\":\"{{context.link}}\"}"
}
}
]
}'
Reference: Create a rule (the page has request
examples for the Elasticsearch query rule with Query DSL, KQL and ES|QL). The same alert as an ES|QL rule replaces searchType,
searchConfiguration and aggType with "searchType": "esqlQuery", "esqlQuery": { "esql": "..." } and "timeField": "@timestamp", with
a query such as FROM logs-*.otel-* | WHERE severity_text == "ERROR" | STATS errors = COUNT(*) | WHERE errors > 20. Switching off
exclude matches from previous run here is deliberate: the rule should keep counting the same burst of errors until it ages out of
the window. The group id query matched is the one the rule type reports; confirm it for your version with GET /s/bookshelf/api/alerting/rule_types.
The index threshold rule
The index threshold rule is the simplest aggregate rule: it takes one or more indices and a time field, aggregates a field over the documents of a time window, compares the result with a threshold and alerts. Compared with the Elasticsearch query rule it has no query language but a plain KQL expression filter, and it always aggregates (count by default).
Its settings are: Indices to query and Time field; When (count, average, sum, min, max; the last four need a numeric field);
Over all documents or Grouped Over a top-N of a grouping field (the number of groups is required, and only those top groups are
checked, which limits alerts on high-cardinality fields); the threshold comparator (is above, is above or equals, is below,
is below or equals, is between; the API also accepts notBetween) and values; For the last, the time window; the optional KQL
filter; the check interval; and the advanced consecutive-runs option (default 1). The action group is Threshold met plus a recovery
group, and the rule-specific variables are {{context.conditions}} (for example "count greater than 4"), {{context.date}},
{{context.group}} (the action group name), {{context.message}}, {{context.title}} and {{context.value}}.
The documentation’s worked example uses the Kibana sample web logs: index kibana_sample_data_logs, time field @timestamp, When
sum of bytes, Over top 4 of host.keyword, is above 420000, For the last 24 hours, checked every 4 hours. The preview
chart shows 30 intervals (120 hours here) and renders only when data exists and all clauses are defined; the page also suggests
comparing a 24-hour window with a 12-hour window, because shorter windows are noisier.
A Bookshelf use that the Observability rules do not cover directly is which route is failing: count 5xx responses per route and alert
for any route above ten in five minutes. The grouping field makes one alert per url.path, so each failing route is its own alert with
its own lifecycle.
curl -s -u elastic:"$ELASTIC_PASSWORD" -X POST "$KIBANA_URL/s/bookshelf/api/alerting/rule/bookshelf-5xx-per-route" \
-H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d '{
"name": "Bookshelf 5xx per route",
"rule_type_id": ".index-threshold",
"consumer": "stackAlerts",
"tags": ["bookshelf", "bookshelf-sre"],
"schedule": { "interval": "1m" },
"alert_delay": { "active": 2 },
"params": {
"index": ["traces-*"],
"timeField": "@timestamp",
"aggType": "count",
"filterKuery": "service.name: \"bookshelf\" and http.response.status_code >= 500",
"groupBy": "top",
"termField": "url.path",
"termSize": 10,
"thresholdComparator": ">",
"threshold": [10],
"timeWindowSize": 5,
"timeWindowUnit": "m"
},
"actions": [
{
"id": "bookshelf-webhook",
"group": "threshold met",
"frequency": { "summary": false, "notify_when": "onActionGroupChange", "throttle": null },
"params": {
"body": "{\"rule\":\"{{rule.name}}\",\"group\":\"{{context.group}}\",\"value\":\"{{context.value}}\",\"conditions\":\"{{context.conditions}}\"}"
}
}
]
}'
Source: Index threshold rule; request properties
from the Create a rule API reference. The
alert_delay of two means two consecutive runs must breach before the alert opens, which absorbs a single bad check. If traces-*
does not carry url.path in your data, use the field Discover shows for the request route.
Tracking containment
The tracking containment rule alerts when an entity enters a boundary or leaves it. It needs two indices. The entities index must
contain a geo_point or geo_shape field, a date field and an entity identifier (keyword, number or ip), and should be kept
current so that movement can trigger alerts. The boundaries index must contain geo_shape data and should be static: boundaries are
collected when the rule is created and again whenever its boundary configuration is modified. On each check the entity locations are
compared with all monitored boundaries; entity data should be near real time, because documents older than the current time minus the
check interval do not trigger the rule. The action groups are Containment condition met (an entity is contained) and Entity no
longer contained (recovery). Rule-specific variables are context.containingBoundaryId and context.containingBoundaryName (not set
for recovered alerts), context.detectionDateTime, context.entityDateTime, context.entityDocumentId, context.entityId and
context.entityLocation. The consecutive-runs option applies as usual.
Bookshelf has no geographic data, so there is no lab alert for this rule; it is the right tool for fleets, deliveries or any entity that moves, and a Maps layer with the same index is the way to look at what it alerts on (Maps, Vega & Other Panels).
Source: Tracking containment.
Transform health
Kibana’s SLOs, and many integrations, depend on Elasticsearch transforms, and a stopped or unhealthy transform fails silently: the
dashboards just stop updating. The transform health rule runs scheduled health checks on continuous transforms. Two checks are
enabled by default: Transform is not started (not started, or not indexing any data) and Unhealthy transform (an unhealthy status,
with the status details and related issues in the notification). You select specific transforms or * for all, and transforms created
later are included automatically. Each alert is named after its transform id, and you can snooze one transform’s alert from the
rule’s alert list (per-alert snooze replaced mute in 9.5). The action groups are issue detected and recovered, and the variables are context.message (for example
"Transform test-1 is not started") and context.results, an array to iterate with Mustache whose items can include transform_id,
description, transform_state, health_status, issues (with issue, count, details and first_occurrence),
failure_reason, notification_message, node_name and timestamp. The documentation does not list a default check interval.
The Bookshelf SLOs of SLOs create transforms named slo-{id}-{revision} and
slo-summary-{id}-{revision}; a transform health rule with the transform selection slo-* is a cheap guard that the SLO numbers
and the burn rate rule are still being fed. The catalogue labels the rule beta while its own page lists it as generally available
for Serverless and the Stack; check the label shown in your Kibana version before relying on it for paging.
Source: Generating alerts for transforms.
What can go wrong
-
A rule fires once and never again although the problem continues: exclude matches from previous run counted only new documents, or the alert is still active and the action frequency is "on status change". Check the alert status before the rule.
-
A rule never fires: a check interval longer than the time window leaves gaps; a time field that is not the one the data uses puts everything outside the window; a data view that matches no data stream.
-
Too many alerts: a grouping field with high cardinality (only the top-N groups are checked, but N can still be large), or per-document alerts on ES|QL ("alert for each row") on a noisy query.
-
A rule fails after someone edits it: the API key now carries that user’s privileges; the Last response column shows
failedand the rule details show the error. -
Imported rules do nothing: exports are disabled and must be re-enabled, which also creates the API key.
-
Wrong group id in an API call: action groups are per rule type (
query matched,threshold met); read them from the rule types endpoint instead of copying. -
A webhook action never arrives: the connector was not created in the same space, the host is blocked by
xpack.actions.allowedHosts, or the receiver is reachable from the host (localhost) but not from the Kibana container (use the service name).
Verify it in the lab
-
Create the connector and the two rules above (the connector first). Open the Rules page in the
bookshelfspace and check that both rules are listed, enabled and show Last responsesucceededafter a minute. -
Fetch a rule as it is stored:
curl -s -u elastic:"$ELASTIC_PASSWORD" "$KIBANA_URL/s/bookshelf/api/alerting/rule/bookshelf-error-log-spike"; noteapi_key_owner(who the rule runs as) andexecution_status. -
Start the load generator in failing-request mode. The 5xx-per-route rule opens one alert per failing route after two consecutive breaching runs; the error-log rule opens one alert once more than 20 error lines are in the five-minute window.
-
Open the rule details and check the alert list, status and duration. Then read what the receiver got (
docker compose logs webhook-receiver): one call per alert status change, because the frequency is "on status change". -
Stop the failing mode and wait out the window; the alerts recover (the recovery group has no action in these rules, so nothing is sent; add one on the actions page).
-
Use Snooze on one rule for 15 minutes, break something again, and confirm that the rule keeps running and creates alerts while the receiver gets nothing.
-
Export both rules from Saved Objects, delete them, import the file and verify that they come back disabled until re-enabled.
In the books
Shah’s Kibana 8.x: A Quick Start Guide to Data Analysis (Packt, 2024) creates a rule from the Rules page and a connector from the Connectors page for an anomaly detection job; the same two objects, a rule and a connector it uses, are what this page automates through the API. The book predates the unified Rules list, per-rule flapping and the ES|QL rule type, and describes a Watcher-first history of alerting that the Classic rules have replaced for new work.
Where to go next
-
Observability Rules: the rule types for metrics, logs, APM and SLOs.
-
Alerting APIs & Terraform for the full API and the provider.
-
Alerting Overview for the model.
-
Querying with KQL, ES|QL & PromQL for the query languages.