Elastic Detection Rules: Types, Tuning and Testing
How Elastic Security detection rules work: the seven rule types, prebuilt rules and the detection-rules repository, scheduling and look-back, why rules go quiet, and how to test them.
Last reviewed November 2026
Elastic detection rules are scheduled searches in Elastic Security that run against your indices on a fixed interval and create an alert for every match.
Elastic publishes more than a thousand prebuilt rules, and the reference material for them is good: the detection-rules repository on GitHub, the rules explorer, and the product documentation. This guide covers what those sources leave to you: choosing a rule type, the scheduling settings that decide whether late events are ever seen, the reasons an enabled rule quietly matches nothing, and how to test a rule against your own data. It is part of our detection engineering guide.
The seven rule types
Elastic Security has seven rule types. Picking the right one matters more than tuning the query inside it.
| Type | What it does | Use it for |
|---|---|---|
| Custom query | A KQL or Lucene query; one alert per matching document | Single-event behaviors: a process, a registry write, a sign-in |
| Event correlation | An EQL query, including sequences of events | Ordered behaviors: a download followed by execution on the same host |
| ES|QL | A piped ES|QL query, with aggregation | Counting, grouping and lookups inside the rule |
| Threshold | Alerts when a field value appears at least N times | Brute force, spraying, bursts of one event type |
| New terms | Alerts the first time a value (or combination) appears within a history window | A user's first sign-in from a new country, a first-seen parent process |
| Indicator match | Matches events against threat intel indicator indices | Known-bad hashes, domains and addresses |
| Machine learning | Alerts on anomaly scores from a machine learning job | Rare or unusual behavior with no fixed signature (needs the right license tier) |
Most teams start with custom query and event correlation rules, and reach for ES|QL when they need to aggregate. New terms rules are underused: "first time this happened in 14 days" catches a lot of behavior that is hard to describe as a fixed query.
Anatomy of a rule
In the detection-rules repository, every rule is a structured text file with a metadata section and a rule section. Custom rules can follow the same format. Here is an event correlation rule for one behavior of the Shai-Hulud npm worm, an install script running TruffleHog to look for secrets:
[metadata]
creation_date = "2026/11/29"
integration = ["endpoint"]
maturity = "production"
[rule]
name = "TruffleHog run by a JavaScript runtime"
description = "TruffleHog launched by Node or Bun, as in the Shai-Hulud npm worm's install script."
rule_id = "6d3f1a52-8c0e-4f7b-9a21-5b4e0c7d2e91"
type = "eql"
language = "eql"
index = ["logs-endpoint.events.process-*"]
interval = "5m"
from = "now-9m" # look back further than the interval
timestamp_override = "event.ingested" # judge lateness by arrival time
risk_score = 73
severity = "high"
query = '''
process where event.type == "start" and
process.parent.name : ("node", "node.exe", "bun", "bun.exe") and
process.command_line : "*trufflehog*" and
not (host.name : "ci-runner-*" and process.command_line : "*/opt/secscan/*")
'''
[[rule.threat]]
framework = "MITRE ATT&CK"
[rule.threat.tactic]
id = "TA0006"
name = "Credential Access"
reference = "https://attack.mitre.org/tactics/TA0006/"
A few things worth noticing. The EQL : operator matches case-insensitively and accepts wildcards, so TruffleHog and trufflehog both match. The exclusion names the one legitimate case (a nightly secret scan on the build runners) as narrowly as possible. And index points at the Elastic Defend process data stream, which only exists if that integration is installed.
The same rule written in ES|QL, with a count per host and command line, is on our detection engineering platform page alongside versions for Splunk, Sentinel, Google SecOps and CrowdStrike. One difference to watch if you port between the two: ES|QL's wildcard matching is case-sensitive, so that version lowercases the command line before matching.
Prebuilt rules
Elastic ships its prebuilt rules as a package that Kibana installs and updates from the Rules page. They are written against the Elastic Common Schema and the data streams Elastic's own integrations produce. Each rule lists the integrations it relates to and the fields it requires, which is the first thing to check before enabling it.
Three habits make prebuilt rules work better:
- Enable by data source, not by severity. Turn on the rules whose integrations you have installed and whose required fields your data populates. Enabling everything produces rules that run on indices that do not exist.
- Tune with exceptions, and own them. Rule exceptions and shared exception lists keep the vendor query intact, so updates still apply. Give every exception a reason and a review date, because each one is a coverage decision.
- Know your edit model. How far you can change a prebuilt rule in place, and what happens to your change when Elastic updates the rule, depends on your version and license. Duplicating a rule to customize it is the portable approach, at the cost of maintaining the copy yourself.
Scheduling, look-back and late data
Every rule runs on an interval (five minutes by default) and searches back to from. If the look-back equals the interval, an event that arrives late, because an agent was offline or a pipeline was backed up, lands in a window the rule has already searched, and it is never seen.
Two settings guard against that:
- Additional look-back. Set
fromfurther back than the interval (now-9mon a five-minute interval, for example). Duplicate alerts from the overlap are de-duplicated. - Timestamp override. Setting it to
event.ingestedmakes the rule judge events by when they arrived in Elasticsearch, not when they happened, so late events fall into the current window.
Also worth knowing: a rule creates at most 100 alerts per run by default (max_signals), alert suppression can collapse repeats by field, and building block rules create low-severity alerts that feed other rules without appearing in the main alert queue.
Why Elastic rules go quiet
An Elastic rule can be enabled, scheduled and reporting success while matching nothing. The common causes:
- The index pattern matches nothing. The integration was never installed, the data stream was renamed, or a custom pipeline writes to an index the pattern does not cover. Check the rule's monitoring tab: missing indices show up as warnings, and warnings are easy to ignore.
- The fields are not populated. The rule expects
process.command_line, and your ingest pipeline keeps the raw field without mapping it to the Elastic Common Schema. The query is valid; it asks about a field that is always empty. - Field types differ. A value mapped as
textin one index andkeywordin another matches differently, and wildcard queries onkeywordfields are case-sensitive. - Partial coverage. The field exists on servers and not on laptops, because a different agent or policy runs there.
- Execution gaps. If Kibana's task manager falls behind, rule runs are delayed or skipped, and the time in between is never searched. The rule monitoring view shows gaps and execution durations.
None of these raise an error. In our Detection Debt Report, 29% of deployed, enabled rules across six SIEM platforms were broken, and silent failures like these are why.
Testing a rule on your own data
- Preview it. The rule creation flow in Kibana can preview a rule over a recent time range and show what it would have alerted on. Run it over at least a week.
- Check the fields first. Before trusting a zero, count recent events in the target index where each field the rule uses is populated. A zero there tells you the rule cannot fire.
- Run a positive control. Generate the behavior on a test host, with an Atomic Red Team test or a script, and confirm an alert appears through your real collection pipeline.
- Watch the first week. Check the alert volume and the rule's execution status after enabling. A rule that never alerts and a rule that alerts 500 times a day both need attention.
- Re-test after changes. Integration upgrades, ingest pipeline edits and agent policy changes are the most common reasons a working rule stops working.
Managing Elastic rules as code
Elastic supports managing rules outside the Kibana console. The detection-rules repository includes a command-line tool for validating and testing rules, and for importing and exporting them to and from Kibana, including your own custom rules. Kibana's detection engine API covers creating, updating, importing and exporting rules, so any pipeline can deploy them. Elastic's own detections as code write-up describes the approach.
If you also write portable rules, Sigma converts to Elastic through pySigma's Elasticsearch backend, which can produce Lucene, EQL or ES|QL. Read the generated query and check the field mapping against your indices before deploying it.
Whichever way you write them, the question for every Elastic rule is the same one: would it fire on your data today, and would you know if it stopped?
Related guides
See what your environment is actually detecting
Spectrum maps your coverage, builds the detections you are missing, and keeps them working.