A hunt query moved from one platform to another can return different results without any error, because the languages disagree on case sensitivity, null handling, join semantics and default row limits. This cheat sheet puts the common hunting operations side by side in four languages: ES|QL (Elastic), KQL (Kusto Query Language, used in Microsoft Sentinel, Defender XDR and Azure Data Explorer), SPL (Splunk Search Processing Language) and SQL (shown in PostgreSQL syntax, the dialect most data lake engines resemble). It covers filtering and time ranges, field selection, aggregation, joins and lookups, string and regex matching and time bucketing, with the semantic traps that change results. It is written for threat hunters and detection engineers working across platforms. Languages are listed alphabetically; the order is not a ranking. Syntax checked against each vendor's documentation in November 2026.
How to use this template
Placeholders: the examples use a generic authentication data set. Replace logs-auth, AuthEvents, index=auth and auth_events with your index, table or view, and field names such as user, src_ip and outcome with your schema (ECS, ASIM, CIM or your own).
Time fields: each column uses the platform's usual timestamp: @timestamp (ES|QL), TimeGenerated (KQL in Log Analytics tables), _time (SPL) and event_time (SQL placeholder).
Read across a row: each row is one operation. Rows are equivalent in intent, but check the gotchas under each table before assuming identical results.
FROM logs-auth | WHERE @timestamp >= NOW() - 24 hours
AuthEvents | where TimeGenerated > ago(24h)
index=auth earliest=-24h
SELECT * FROM auth_events WHERE event_time >= now() - interval '24 hours'
Equals
WHERE outcome == "failure"
where Outcome == "failure"
outcome=failure
WHERE outcome = 'failure'
Not equals
WHERE outcome != "success"
where Outcome != "success"
outcome!=success
WHERE outcome <> 'success'
In a list
WHERE user IN ("svc_backup", "svc_deploy")
where User in~ ("svc_backup", "svc_deploy")
user IN (svc_backup, svc_deploy)
WHERE user_name IN ('svc_backup', 'svc_deploy')
Field exists or is null
WHERE src_ip IS NOT NULL
where isnotempty(SrcIp)
src_ip=*
WHERE src_ip IS NOT NULL
Limit rows
LIMIT 100
take 100
head 100
LIMIT 100
ES|QL: Elastic documents that WHERE field != "value" is interpreted as also requiring the field to be not null, and that a query returns up to 1,000 rows by default, raised to at most 10,000 with LIMIT.
KQL:==, != and in are case-sensitive; =~, !~ and in~ are case-insensitive.
SPL:outcome!=success returns only events that have the field; NOT outcome=success also returns events without it. Use CASE() where search terms or field values must match case-sensitively.
SQL:<> never matches NULL, so add OR outcome IS NULL if missing values should count.
Field selection and renaming
Operation
ES|QL
KQL
SPL
SQL (PostgreSQL)
Keep columns, in order
KEEP @timestamp, user, src_ip
project TimeGenerated, User, SrcIp
table _time user src_ip
SELECT event_time, user_name, src_ip
Drop columns
DROP message
project-away Message
fields - message
List only the columns you want in SELECT
Rename
RENAME src_ip AS source
project-rename Source = SrcIp
rename src_ip AS source
SELECT src_ip AS source
Computed column
EVAL is_svc = user LIKE "svc_*"
extend IsSvc = User startswith "svc_"
eval is_svc=if(like(user,"svc_%"),1,0)
SELECT user_name LIKE 'svc\_%' AS is_svc
Wildcard columns
KEEP user*
project-keep User*
fields user*
List the columns explicitly in SELECT
Rename direction differs: ES|QL and SPL write old AS new; KQL project-rename writes new = old. ES|QL also accepts new = old from stack version 9.1. In ES|QL, renaming to an existing column name drops the existing column.
Underscore in SQL LIKE:_ matches any single character in SQL and in SPL's like(), so escape it when you mean a literal underscore.
Aggregation and counting
Operation
ES|QL
KQL
SPL
SQL (PostgreSQL)
Count by field
STATS c = COUNT(*) BY user
summarize c = count() by User
stats count AS c by user
SELECT user_name, COUNT(*) AS c FROM auth_events GROUP BY user_name
Distinct count
STATS hosts = COUNT_DISTINCT(host) BY user
summarize Hosts = dcount(Host) by User
stats dc(host) AS hosts by user
SELECT user_name, COUNT(DISTINCT host) AS hosts ... GROUP BY user_name
List of values
STATS ips = VALUES(src_ip) BY user
summarize Ips = make_set(SrcIp) by User
stats values(src_ip) AS ips by user
SELECT user_name, array_agg(DISTINCT src_ip) ... GROUP BY user_name
Filter on the aggregate
STATS c = COUNT(*) BY user | WHERE c > 20
summarize c = count() by User | where c > 20
stats count AS c by user | where c > 20
GROUP BY user_name HAVING COUNT(*) > 20
Top 10
SORT c DESC | LIMIT 10
top 10 by c desc
sort - c | head 10
ORDER BY c DESC LIMIT 10
Approximate distinct counts: Elastic states COUNT_DISTINCT returns an approximate number, and Microsoft states dcount() returns an estimate that can vary between executions. COUNT(DISTINCT ...) in PostgreSQL is exact. For thresholds on small numbers (for example "more than 3 hosts"), confirm borderline results with an exact method.
Value lists: Elastic notes the order of VALUES output is not guaranteed; KQL make_set takes an optional maximum size. Do not rely on list order in any language.
Joins and lookups
Joins are where translated hunts most often diverge, because the default join type and the handling of duplicates differ.
Aspect
ES|QL
KQL
SPL
SQL (PostgreSQL)
Enrichment syntax
LOOKUP JOIN asset_owners ON host
lookup kind=leftouter (AssetOwners) on Host
lookup asset_owners host OUTPUT owner
LEFT JOIN asset_owners o ON o.host = e.host
Event to event join
LOOKUP JOIN against an index in lookup mode
join kind=inner (OtherTable) on $left.User == $right.Account
join type=inner user [search index=vpn]
JOIN vpn_events v ON v.user_name = e.user_name
Default behaviour
Left join: unmatched rows kept with nulls; one output row per lookup match
join defaults to innerunique, which deduplicates left rows; lookup defaults to leftouter
join defaults to inner with max=1, the first matching row only
JOIN is inner and returns every matching combination
Documented limits
Lookup index must use the lookup index mode; no wildcards in the lookup index name; multi-valued join keys match nothing
lookup broadcasts the right table, so keep it small; put the smaller table on the left of join
Subsearch capped by default at 50,000 rows and 60 seconds (subsearch_maxout, subsearch_maxtime)
No built-in row cap; cost depends on indexes and plan
Case of join keys
Exact value match; normalise with TO_LOWER first
Exact value match; normalise with tolower() first
Case-sensitive; normalise with lower() in eval on both sides
Exact under the default collation; normalise with lower()
ES|QL status:LOOKUP JOIN is listed as generally available from stack 9.1 (technical preview in 9.0) and in Serverless; some join-condition forms are still marked preview.
Silent truncation: an SPL join whose subsearch exceeds its limit and a KQL default join that collapses duplicate left rows both return results without error. Prefer stats by a shared key in SPL, and specify kind=inner in KQL when you need every match.
String and regex functions
Operation
ES|QL
KQL
SPL
SQL (PostgreSQL)
Contains, ignoring case
WHERE TO_LOWER(cmdline) LIKE "*encodedcommand*"
where CmdLine contains "encodedcommand"
cmdline="*encodedcommand*"
WHERE cmdline ILIKE '%encodedcommand%'
Starts with
WHERE user LIKE "svc_*"
where User startswith "svc_"
user=svc_*
WHERE user_name LIKE 'svc\_%'
Regex match
WHERE host RLIKE "web-[0-9]+"
where Host matches regex @"web-\d+"
| regex host="web-\d+"
WHERE host ~ 'web-\d+'
Extract with regex
GROK msg "%{IP:client_ip}" or DISSECT
extend ClientIp = extract(@"from (\S+)", 1, Msg)
rex field=msg "from (?<client_ip>\S+)"
SELECT (regexp_match(msg, 'from (\S+)'))[1] AS client_ip
Lower case
TO_LOWER(user)
tolower(User)
lower(user)
lower(user_name)
ES|QL: Elastic documents that LIKE and RLIKE on text fields treat the field as a keyword without the analyser, so matching is case-sensitive and must match the exact indexed string; wildcards are * and ?. Use MATCH or QSTR for full-text search.
KQL:contains is case-insensitive substring; has matches whole terms using the term index and is faster, but "KustoExplorerQueryRun" has "Explorer" is false. matches regex is case-sensitive. Operators with an _cs suffix are case-sensitive.
SPL: wildcards in the base search use *; in where and eval, like() uses % and comparisons are case-sensitive. rex defaults to _raw when no field is given and matches once unless max_match is set.
SQL: PostgreSQL LIKE is case-sensitive; ILIKE is a PostgreSQL extension, as is ~* for case-insensitive regex. Other engines use different functions (for example REGEXP_LIKE or RLIKE), so check your engine's reference.
Time bucketing
Operation
ES|QL
KQL
SPL
SQL (PostgreSQL)
Count per hour
STATS c = COUNT(*) BY hour = BUCKET(@timestamp, 1 hour)
summarize c = count() by bin(TimeGenerated, 1h)
bin _time span=1h | stats count by _time
SELECT date_trunc('hour', event_time) AS hour, COUNT(*) ... GROUP BY 1
STATS c = COUNT(*) BY user, hour = BUCKET(@timestamp, 1 hour)
summarize c = count() by User, bin(TimeGenerated, 1h)
bin _time span=1h | stats count by user _time
GROUP BY user_name, date_trunc('hour', event_time)
Truncate a timestamp
EVAL day = DATE_TRUNC(1 day, @timestamp)
extend Day = startofday(TimeGenerated)
eval day=relative_time(_time, "@d")
date_trunc('day', event_time)
Chart over time
STATS ... BY BUCKET(...) then visualise
... | render timechart
timechart span=1h count by user
Group by bucket, then chart in the client
Empty buckets: grouping returns only intervals that have data in all four languages unless you fill gaps (for example SPL timechart creates the series, KQL offers make-series). Missing intervals matter for "silence" detections.
Time zones: confirm whether timestamps are stored in UTC and how the console displays them before comparing hourly counts across platforms.
Implementation guidance
Semantic gotchas at a glance
Behaviour
ES|QL
KQL
SPL
SQL (PostgreSQL)
Default string equality
Case-sensitive
== case-sensitive; =~ insensitive
Base search insensitive; where and eval case-sensitive
Case-sensitive under deterministic collations
Not equals and missing fields
!= excludes nulls
Check empty values with isempty()
!= excludes events without the field; NOT includes them
<> excludes NULL
Default rows returned
1,000 unless LIMIT set (max 10,000)
Set by the client or service; add take explicitly
Set by search settings and commands such as head
All rows unless LIMIT set
Distinct count
Approximate
dcount() estimate
dc()
Exact
Sigma as the neutral layer
For detections you maintain across platforms, write the logic once in Sigma and convert, rather than hand-translating each query. The SigmaHQ Sigma Rules Specification (version 2.1.0, release date 2 August 2025) treats values as case-insensitive strings and regular expressions as case-sensitive by default; each backend has to reproduce that, which is why converted queries often add lower-casing or case-insensitive operators. The sigma convert -t <backend> -p <pipeline> command in sigma-cli produces the target query; backends exist for Splunk (splunk), Elastic (including an esql target in the Elasticsearch backend), Kusto (the pySigma Kusto backend, which its README marks as pre-release) and SQLite for SQL. Processing pipelines map Sigma's field names to your schema. See the Sigma Rule Syntax Cheat Sheet and Sigma Rules Guide.
Translating a hunt safely
Write down the intent in one sentence (for example "users with failed sign-ins from more than five source IPs in an hour").
Map field names and value formats between schemas first; most mistranslations are schema, not syntax.
Translate using the rows above, normalising case explicitly in comparisons and join keys.
Run both versions on the same known sample and compare counts per group; investigate any difference before deploying.
Record the tested query, platform version and sample result with the hunt in your Threat Hunt Hypothesis and Report Template, and keep the original so you can roll back.
Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.