Performs set operations on subsearches.
set (union|diff|intersect) subsearch subsearch
- Syntax: <string>
- Description: Specifies a subsearch. For more information about subsearch syntax, see "About subsearches" in the Search manual.
Performs two subsearches and then executes the specified set operation on the two sets of search results:
- The result of a union operation are events that result from either subsearch.
- The result of a diff operation are the events that result from either subsearch that are not common to both.
- The result of an intersect operation are the events that are common for both subsearches.
Important: The set command works on less than 10 thousand results.
Example 1: Return values of "URL" that contain the string "404" or "303" but not both.
| set diff [search 404 | fields url] [search 303 | fields url]
Example 2: Return all urls that have 404 errors and 303 errors.
| set intersect [search 404 | fields url] [search 303 | fields url]
Note: When you use the
fields command in your subsearches, it does not filter out internal fields by default. If you don't want the
set command to compare internal fields, such as the
_time fields, you need to explicitly exclude them from the subsearches:
| set intersect [search 404 | fields url | fields - _*] [search 303 | fields url | fields - _*]
Have questions? Visit Splunk Answers and see what questions and answers the Splunk community has using the set command.