Wildcards and exists
10 min · 2 ejercicio(s)
Wildcards
An asterisk * matches any number of characters:
process.name: power*
user_agent.original: sqlmap*Wildcards work best at the end of a value. A leading wildcard (*shell.exe) is possible but expensive on large clusters.
Does a field exist?
field: * matches every document that has a value in this field:
url.query: *Escaping
Windows paths are full of backslashes, and a colon is special in KQL. Escape special characters with a backslash, so a single \ in the path becomes \\:
file.path: C\:\\Windows\\Temp\\*If you don't need a wildcard, quoting is easier: file.path: "C:\\Windows\\Temp\\lsass.dmp". Inside quotes you only escape " and \.
🔎 Profundiza: funciones, errores habituales y práctica
Wildcard rules
| Pattern | Matches | Note |
|---|---|---|
power* |
powershell.exe, powerpnt.exe | trailing wildcard, fast |
*shell.exe |
powershell.exe, pwsh… | leading wildcard, slow on big data |
*Temp* |
anything containing Temp | slowest form |
process.*: rundll32* |
the value in any process field | wildcard in the field name |
field: * |
field exists | also matches empty strings in keywords |
KQL has only *. There is no single-character wildcard (? is a literal character) and no regular expression. For regex switch to Lucene syntax or ES|QL RLIKE.
Why leading wildcards are slow
Elasticsearch stores keywords in a sorted dictionary. power* jumps directly to the right place, *shell has to scan every term. On a few million events this is noticeable, on billions it can time out. Fields mapped as wildcard type (used by Elastic for process.command_line in endpoint data) are optimised for this case.
Escaping cheat sheet
| You want to find | Write |
|---|---|
C:\Windows\Temp\* (wildcard) |
C\:\\Windows\\Temp\\* |
C:\Windows\Temp\lsass.dmp (exact) |
"C:\\Windows\\Temp\\lsass.dmp" |
| a literal asterisk | \* |
(test) |
\(test\) or "(test)" |