Join our Newsletter — 33% off our NHI Course
Home› Guides› Security Query Languages Translation Cheat Sheet: KQL, SPL,…
Template SOC & Detection Engineering

Security Query Languages Translation Cheat Sheet: KQL, SPL, ES|QL and SQL Equivalents

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 27 November 2026 11 min read
On this page

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.
  • Test before trusting: run each translated query against a small, known sample and compare counts with the original. The KQL for Threat Hunting Guide and Splunk SPL for Threat Hunting Guide go deeper on single languages.

Filtering and time ranges

OperationES|QLKQLSPLSQL (PostgreSQL)
Source and last 24 hoursFROM logs-auth | WHERE @timestamp >= NOW() - 24 hoursAuthEvents | where TimeGenerated > ago(24h)index=auth earliest=-24hSELECT * FROM auth_events WHERE event_time >= now() - interval '24 hours'
EqualsWHERE outcome == "failure"where Outcome == "failure"outcome=failureWHERE outcome = 'failure'
Not equalsWHERE outcome != "success"where Outcome != "success"outcome!=successWHERE outcome <> 'success'
In a listWHERE 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 nullWHERE src_ip IS NOT NULLwhere isnotempty(SrcIp)src_ip=*WHERE src_ip IS NOT NULL
Limit rowsLIMIT 100take 100head 100LIMIT 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

OperationES|QLKQLSPLSQL (PostgreSQL)
Keep columns, in orderKEEP @timestamp, user, src_ipproject TimeGenerated, User, SrcIptable _time user src_ipSELECT event_time, user_name, src_ip
Drop columnsDROP messageproject-away Messagefields - messageList only the columns you want in SELECT
RenameRENAME src_ip AS sourceproject-rename Source = SrcIprename src_ip AS sourceSELECT src_ip AS source
Computed columnEVAL 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 columnsKEEP 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

OperationES|QLKQLSPLSQL (PostgreSQL)
Count by fieldSTATS c = COUNT(*) BY usersummarize c = count() by Userstats count AS c by userSELECT user_name, COUNT(*) AS c FROM auth_events GROUP BY user_name
Distinct countSTATS hosts = COUNT_DISTINCT(host) BY usersummarize Hosts = dcount(Host) by Userstats dc(host) AS hosts by userSELECT user_name, COUNT(DISTINCT host) AS hosts ... GROUP BY user_name
List of valuesSTATS ips = VALUES(src_ip) BY usersummarize Ips = make_set(SrcIp) by Userstats values(src_ip) AS ips by userSELECT user_name, array_agg(DISTINCT src_ip) ... GROUP BY user_name
Filter on the aggregateSTATS c = COUNT(*) BY user | WHERE c > 20summarize c = count() by User | where c > 20stats count AS c by user | where c > 20GROUP BY user_name HAVING COUNT(*) > 20
Top 10SORT c DESC | LIMIT 10top 10 by c descsort - c | head 10ORDER 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.

AspectES|QLKQLSPLSQL (PostgreSQL)
Enrichment syntaxLOOKUP JOIN asset_owners ON hostlookup kind=leftouter (AssetOwners) on Hostlookup asset_owners host OUTPUT ownerLEFT JOIN asset_owners o ON o.host = e.host
Event to event joinLOOKUP JOIN against an index in lookup modejoin kind=inner (OtherTable) on $left.User == $right.Accountjoin type=inner user [search index=vpn]JOIN vpn_events v ON v.user_name = e.user_name
Default behaviourLeft join: unmatched rows kept with nulls; one output row per lookup matchjoin defaults to innerunique, which deduplicates left rows; lookup defaults to leftouterjoin defaults to inner with max=1, the first matching row onlyJOIN is inner and returns every matching combination
Documented limitsLookup index must use the lookup index mode; no wildcards in the lookup index name; multi-valued join keys match nothinglookup broadcasts the right table, so keep it small; put the smaller table on the left of joinSubsearch 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 keysExact value match; normalise with TO_LOWER firstExact value match; normalise with tolower() firstCase-sensitive; normalise with lower() in eval on both sidesExact 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

OperationES|QLKQLSPLSQL (PostgreSQL)
Contains, ignoring caseWHERE TO_LOWER(cmdline) LIKE "*encodedcommand*"where CmdLine contains "encodedcommand"cmdline="*encodedcommand*"WHERE cmdline ILIKE '%encodedcommand%'
Starts withWHERE user LIKE "svc_*"where User startswith "svc_"user=svc_*WHERE user_name LIKE 'svc\_%'
Regex matchWHERE host RLIKE "web-[0-9]+"where Host matches regex @"web-\d+"| regex host="web-\d+"WHERE host ~ 'web-\d+'
Extract with regexGROK msg "%{IP:client_ip}" or DISSECTextend ClientIp = extract(@"from (\S+)", 1, Msg)rex field=msg "from (?<client_ip>\S+)"SELECT (regexp_match(msg, 'from (\S+)'))[1] AS client_ip
Lower caseTO_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

OperationES|QLKQLSPLSQL (PostgreSQL)
Count per hourSTATS c = COUNT(*) BY hour = BUCKET(@timestamp, 1 hour)summarize c = count() by bin(TimeGenerated, 1h)bin _time span=1h | stats count by _timeSELECT date_trunc('hour', event_time) AS hour, COUNT(*) ... GROUP BY 1
Arbitrary intervalBUCKET(@timestamp, 15 minutes)bin(TimeGenerated, 15m)bin _time span=15mdate_bin('15 minutes', event_time, TIMESTAMP '2001-01-01')
Per entity per intervalSTATS 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 _timeGROUP BY user_name, date_trunc('hour', event_time)
Truncate a timestampEVAL day = DATE_TRUNC(1 day, @timestamp)extend Day = startofday(TimeGenerated)eval day=relative_time(_time, "@d")date_trunc('day', event_time)
Chart over timeSTATS ... BY BUCKET(...) then visualise... | render timecharttimechart span=1h count by userGroup 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

BehaviourES|QLKQLSPLSQL (PostgreSQL)
Default string equalityCase-sensitive== case-sensitive; =~ insensitiveBase search insensitive; where and eval case-sensitiveCase-sensitive under deterministic collations
Not equals and missing fields!= excludes nullsCheck empty values with isempty()!= excludes events without the field; NOT includes them<> excludes NULL
Default rows returned1,000 unless LIMIT set (max 10,000)Set by the client or service; add take explicitlySet by search settings and commands such as headAll rows unless LIMIT set
Distinct countApproximatedcount() estimatedc()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

  1. Write down the intent in one sentence (for example "users with failed sign-ins from more than five source IPs in an hour").
  2. Map field names and value formats between schemas first; most mistranslations are schema, not syntax.
  3. Translate using the rows above, normalising case explicitly in comparisons and join keys.
  4. Run both versions on the same known sample and compare counts per group; investigate any difference before deploying.
  5. 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.

Standards and references

Related NHI Mgmt Group resources: KQL for Threat Hunting Guide · Splunk SPL for Threat Hunting Guide · Elastic Security Guide · PostgreSQL Security Guide · Threat Hunting Guide

PDF for subscribers

Take this guide with you

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.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.