Home / Search/ Language Reference/ Operators/ Filter Operators/where

where

The where operator filters events based on the specified predicate.

Syntax

Scope | where Predicate

Arguments

  • Scope: The events to search.
  • Predicate: An expression that returns a bool value for each event. This can match on strings, numeric values, or regular expressions.

Comparison and String Operators in where

You can construct a Predicate using the comparison and string operators shown below. Note the abbreviations used in these tables:

  • Operators with a _cs suffix are case-sensitive.
  • RHS = right-hand side of the predicate.
  • LHS = left-hand side of the predicate.

Comparison Operators in where

To compare on wildcards (*), use the comparison operators of the cribl operator. The where operator supports wildcards only inside regex literals (/^abc.*xyz$/).

When comparing values of different types, Cribl Search performs automatic type conversion wherever possible, giving priority to number comparisons.

Some comparison examples:

  • “1.0” == 1 is true
  • “1.0” == “1” is true
  • 5 < 100 is true
  • “5” < “100” is true
  • “abc” < “100” is false
  • “abc” < 100 is null
OperatorDescriptionExample (Returns true)Case-SensitiveAccepts nullSupports RegexRegex Example
==Equals"aBc" == "aBc"YesYesOnly in regex literalsfoo == /^abc.*xyz$/
!=Not equals"abc" != "ABC"YesYesOnly in regex literalsfoo != /^abc.*xyz$/
=~Equals"abc" =~ "ABC"NoYesOnly in regex literalsfoo =~ /^abc.*xyz$/
!~Not equals"aBc" !~ "xyz"NoYesOnly in regex literalsfoo !~ /^abc.*xyz$/
>Greater thanNo
<Less thanNo
>=Greater than or equal toNo
<=Less than or equal toNo
!Unary inversion (NOT)

Logical values only;
string values are unsupported
No

String Operators in where

To search on wildcards (*), use the string operators of the cribl operator. The where operator supports wildcards only inside regex literals (/^abc.*xyz$/).

OperatorDescriptionExample (Returns true)Case-SensitiveRegexRegex Example
containsRHS occurs as a subsequence of LHS"FabriKam" contains "BRik"NoNo
!containsRHS doesn’t occur in LHS"Fabrikam" !contains "xyz"NoNo
contains_csRHS occurs as a subsequence of LHS"FabriKam" contains_cs "Kam"YesNo
!contains_csRHS doesn’t occur in LHS"Fabrikam" !contains_cs "Kam"YesNo
endswithRHS is a closing subsequence of LHS"Fabrikam" endswith "Kam"NoNo
!endswithRHS isn’t a closing subsequence of LHS"Fabrikam" !endswith "brik"NoNo
endswith_csRHS is a closing subsequence of LHS"Fabrikam" endswith_cs "kam"YesNo
!endswith_csRHS isn’t a closing subsequence of LHS"Fabrikam" !endswith_cs "brik"YesNo
hasRight-hand-side (RHS) is a whole term in left-hand-side (LHS)"North America" has "america"NoNo
:Alias for has"North America" : "america"NoNo
!hasRHS isn’t a full term in LHS"North America" !has "amer"NoNo
has_allSame as has but works on all of the events"North and South America" has_all("south", "north")NoNo
has_anySame as has but works on any of the events"North America" has_any("south", "north")NoNo
!has_allSame as has but works on all of the events"North and South America" has_all("south", "north")NoNo
!has_anySame as has but works on any of the events"North America" has_any("south", "north")NoNo
has_csRHS is a whole term in LHS"North America" has_cs "America"YesNo
!has_csRHS isn’t a full term in LHS"North America" !has_cs "amer"YesNo
hasprefixRHS is a term prefix in LHS"North America" hasprefix "ame"NoNo
!hasprefixRHS isn’t a term prefix in LHS"North America" !hasprefix "mer"NoNo
hasprefix_csRHS is a term prefix in LHS"North America" hasprefix_cs "Ame"YesNo
!hasprefix_csRHS isn’t a term prefix in LHS"North America" !hasprefix_cs "CA"YesNo
hassuffixRHS is a term suffix in LHS"North America" hassuffix "ica"NoNo
!hassuffixRHS isn’t a term suffix in LHS"North America" !hassuffix "americ"NoNo
hassuffix_csRHS is a term suffix in LHS"North America" hassuffix_cs "ica"YesNo
!hassuffix_csRHS isn’t a term suffix in LHS"North America" !hassuffix_cs "icA"YesNo
inEqual to any of the events"abc" in ("123", "345", "abc")YesOnly in regex literalsfoo in ("ye*ah", /^no.+way/i, 'whee')
!inNot equal to any of the events"bca" !in ("123", "345", "abc")YesOnly in regex literalsfoo !in ("ye*ah", /^no.+way/i, 'whee')
in~Equal to any of the events"Abc" in~ ("123", "345", "abc")NoOnly in regex literalsfoo in~ ("ye*ah", /^no.+way/i, 'whee')
!in~Not equal to any of the events"bCa" !in~ ("123", "345", "ABC")NoOnly in regex literalsfoo !in~ ("ye*ah", /^no.+way/i, 'whee')
matches regexLHS contains a match for RHS"Fabrikam" matches regex "b.*k"YesOnly in regex literalsfoo matches regex /^some.+(body|thing)$/i
startswithRHS is an initial subsequence of LHS"Fabrikam" startswith "fab"NoNo
!startswithRHS isn’t an initial subsequence of LHS"Fabrikam" !startswith "kam"NoNo
startswith_csRHS is an initial subsequence of LHS"Fabrikam" startswith_cs "Fab"YesNo
!startswith_csRHS isn’t an initial subsequence of LHS"Fabrikam" !startswith_cs "fab"YesNo

Results

Returns events for which the Predicate evaluates to true.

Examples

Here are a few examples of how to use the where operator in queries.

Simple Comparisons First

This example retrieves events that are no older than 1 hour, come from a source called MyCluster, and have two fields containing the same value:

dataset=myDataset
| where Timestamp > ago(1h)
    and Source == "MyCluster"
    and ActivityId == SubActivityId

Columns Contain String

Retrieve all the events in which the word “Cribl” appears on word boundaries in field:

dataset=myDataset
| where field has "Cribl"

In where string comparisons, note that : is a substitute for the has operator. So in the above example, where field:"Cribl" is equivalent to where field has "Cribl".

Match on AND Condition

Return results where the field event is greater than 20 and parity is odd.

dataset=$vt_dummy event<100
| extend parity=iif(event%2==0, 'even', 'odd')
| where event>20 and parity=='odd'

Match on OR Condition

Return results that match either of two conditions:

dataset="cribl_internal_logs" | limit 50 | where method == "GET" or method == "POST"

Match with Regex

The where operator supports regular expressions to match against strings or regex literals. You can see this in action in our Regex Examples.

Search on Non-String Values

When using where to search on non-string values (such as int numbers), omit the quotes ("", ''). For example, instead of dataset=$vt_dummy event<"10", do this:

dataset=$vt_dummy event<10

An exception to this is searching for high-precision decimal numbers.