has vs contains
Both operators look for text inside a string, and both ignore case by default. The difference is what counts as a match.
containsmatches any substring, anywhere:"webadmins" contains "admin"is true.hasmatches whole terms. Kusto splits text into terms at every character that is not a letter or a digit (spaces, dots, dashes, slashes,@,_, and so on)."webadmins" has "admin"is false, while"it-admin@corp.example" has "admin"is true, becauseadminis a term there.
| Text | has "admin" |
contains "admin" |
|---|---|---|
it-admin@corp.example |
true | true |
webadmins |
false | true |
cadmium |
false | true |
ADMIN |
true | true |
Which one to use
hasis the better default in real workspaces. Kusto indexes terms, sohasis much faster on big tables, and it avoids accidental matches inside longer words.- Use
containswhen you need part of a term: a fragment of a file name, a parameter written in several ways, or a string that starts with punctuation.
Case and negation
- Add
_csfor a case-sensitive search:has_cs,contains_cs. - Put
!in front for “does not”:!has,!contains,!has_cs,!contains_cs. - For a match at the start or end of the string, see
startswithandendswith. - For patterns, see
matches regex.
Things to know
- A value with punctuation inside, like
has "cmd.exe", matches the textcmd.exeas long as it is not part of a longer term on either side:xcmd.exedoes not match. - A search for a value that is an exact field value is clearer and faster with
==or=~.
Examples
DeviceNetworkEvents
| summarize HasCloud = countif(RemoteUrl has "cloud"), ContainsCloud = countif(RemoteUrl contains "cloud"), HasCloudsuite = countif(RemoteUrl has "cloudsuite")cloud is only part of the term cloudsuite in chat.cloudsuite.example, so has doesn't match it, but contains does.
print Text = "powershell.exe -ExecutionPolicy Bypass"
| extend HasPolicy = Text has "policy", ContainsPolicy = Text contains "policy", HasWholeTerm = Text has "executionpolicy", HasCs = Text has_cs "bypass"ExecutionPolicy is one term; has ignores case but needs the whole term. has_cs also checks case, so lower-case bypass fails.
DeviceNetworkEvents
| where RemoteUrl has "cloudsuite"
| summarize Connections = count() by RemoteUrlPractice it
+ 3 in the full SC-200 set · all exercises