where
Use the where operator to filter results.
Syntax
Note: AQL boolean arguments are case-insensitive, that is, all the following boolean arguments are valid:
Positive case: True, true, t
Negative case: False, false, f
|where <Boolean expression>
Typically, the where operator specifies a logical expression to evaluate field-value matching:
|where <field> <operator> <value>
|where [<field>] [earliest|latest]=[period], [earliest|latest]=[period]
|where [<field>] [earliest|latest]=[period] AND [earliest|latest]=[period]
|where timerange([period], [period], [field])
|where isnotnull(<field>)
|where isnull(<field>)
|where isnum(<field>)
|where isoutlier(<field>, [param], [uselower])
|where like(<field>, <pattern>)
|where match(<field>, <regex>)
|where mvfind(<field>, <regex>)
For subsearch: | where [<field>] | [your_subsearch]
<field>
|
|
<operator>
|
|
<value>
|
The event log value. |
[your_subsearch]
|
The subsearch embedded within the primary search, inside square brackets ( [] ). See Subsearch documentation for more information. |
|
|
Specify a time range expression in the AQL query instead of passing the time range selected with the Search user interface.
Absolute time strings must be in the format:
Examples:
Subsearch: You can define a time range for subsearch that is different from the range for the primary search. See Subsearch documentation for more information.
|
|where timerange([period], [period], [field])
|
Specify a time range expression in the AQL query instead of passing the time range selected with the Search user interface.
Examples:
|
|
|
Filter results to exclude logs having null values for the specified field; or to return only logs having null values for the specified field. Example:
|
|
|
Filter results to include only logs having number values for the specified field. Example:
|
|
|
Filter results to include those where values for the specified field are outliers. Optional:
Examples:
|
|
|
Filter results to include only logs having values for the specified field that match the specified pattern. The pattern can specify an exact match or a wildcard match:
Refer to the Examples section below. |
|
|
Filter results to include only logs having values for the specified field that match the specified regex. Example:
|
|
|
Filter results to include only logs having values that match the Example:
|
Usage
Use the where operator to build complex filters to focus on data that impacts your business.
Evaluation of logical operators
You can create compound filters with use of parentheses, Boolean NOT, Boolean AND, or Boolean OR clauses.
Search evaluates the logical operator in the following descending order (first to last evaluation):
-
Parentheses ()
-
Comparison operators (=, !=, <, >, <=, >=)
-
Logical NOT (NOT)
-
Logical AND (AND)
-
Logical OR (OR)
Example 1: Search with AND and OR
The Search query
| where category != '' or src = '50.1.114.34' and sourcetype = 'ts_cloud'
during evaluation becomes
| where (category != '') or (src = '50.1.114.34' and sourcetype = 'ts_cloud')
This means that the condition src = '50.1.114.34' and sourcetype = 'ts_cloud' will be evaluated first, and then the result will be combined with category != '' using the OR operator.
Example 2: Search with NOT, AND and OR
The Search query
| where event_time NOT IN (9, 10) AND sourcetype contains_ci ('aws') or sourcetype contains_ci ('fortinet') and sourcetype = 'abc'
during evaluation becomes
| where (event_time NOT IN (9, 10) AND sourcetype contains_ci('aws')) or (sourcetype contains_ci ('fortinet') and sourcetype = 'abc')
This means that the condition event_time NOT IN (9, 10) AND sourcetype contains_ci('aws') will be evaluated first, and then the result will be combined with (sourcetype contains_ci ('fortinet') and sourcetype = 'abc') using the OR operator.
Examples
Example 1: Filters events to CrowdStrike logs where the process image is pnputil.exe, a Windows utility sometimes abused for malicious driver installation.
|where sourcetype contains "CrowdStrike" and image endswith "\pnputil.exe"
Example 2: Filters events to internal traffic originating from the 192.168.0.0/16 subnet where the destination is both non-null and non-empty — effectively guarding against incomplete or malformed network flow records.
|where (src insubnet '192.168.0.0/16' and dest is not null) AND (src insubnet '192.168.0.0/16' and dest !='')
Example 3: Filters events to Cisco logs that have a non-null source IP.
|where sourcetype contains "cisco" and src_ip is not null
Example 4: Filters OCSF events to Fortigate products, takes the first 20, splits the product name into a multi-value field on spaces, then calculates how many words are in each product name.
ocsf | fields metadata.product.name | where metadata.product.name contains 'Fortigate' | limit 20 | makemv delim = ' ' metadata.product.name | calc mv_len = array_len(metadata.product.name_mv)