
set
Description
Performs set operations on subsearches.
Syntax
| set (union | diff | intersect) subsearch subsearch
Required arguments
- union | diff | intersect
- Syntax: union | diff | intersect
- Description: Performs two subsearches, then executes the specified set operation on the two sets of search results.
- * Specify
union
to return results from either subsearch. - * Specify
diff
to return results from only one of the two subsearches. There is no information provided as to which subsearch the results originated from. - * Specify
intersect
to return results that are common to both subsearches.
- subsearch
- Syntax: "[" <string> "]"
- Description: Specifies a subsearch. Subsearches must be enclosed in square brackets. For more information about subsearch syntax, see "About subsearches" in the Search Manual.
Usage
The set
command is an event-generating command. See Command types.
Generating commands use a leading pipe character and should be the first command in a search.
Results
The set
command considers results to be the same if all of fields that the results contain match. Some internal fields generated by the search, such as _serial, vary from search to search. You need to filter out some of the fields if you are using the set
command with raw events, as opposed to transformed results such as those from a stats
command. Typically in these cases, all fields are the same from search to search.
Output limitations
There is a limit on the quantity of results that come out of the invoked subsearches that the set
command receives to operate on. If this limit is exceeded, the input result set to the diff
command is silently truncated.
If you have Splunk Enterprise, you can adjust this limit by editing the limits.conf
file and changing the maxout
value in the [subsearch]
stanza. If this value is altered, the default quantity of results coming from a variety of subsearch scenarios are altered. Note that very large values might cause extensive stalls during the 'parsing' phase of a search, which is when subsearches run. The default value for this limit is 10000.
Only users with file system access, such as system administrators, can edit the configuration files. Never change or copy the configuration files in the default directory. The files in the default directory must remain intact and in their original location. Make the changes in the local directory.
See How to edit a configuration file.
If you are using Splunk Cloud and want to edit a configuration file, file a Support ticket.
Result rows limitations
By default the set
command attempts to traverse a maximum of 50000 items from each subsearch. If the number of input results from either search exceeds this limit, the set
command silently ignores the remaining events. By default, the maxout setting for subsearches prevents the number of results from exceeding this limit.
This maximum is controlled by the maxresultrows
setting in the [set] stanza in the limits.conf file. Increasing this limit can result in more memory usage.
Only users with file system access, such as system administrators, can edit the configuration files. Never change or copy the configuration files in the default directory. The files in the default directory must remain intact and in their original location. Make the changes in the local directory.
See How to edit a configuration file.
If you are using Splunk Cloud and want to edit a configuration file, file a Support ticket.
Examples
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 do not want the set
command to compare internal fields, such as the _raw
or _time
fields, you need to explicitly exclude them from the subsearches:
| set intersect [search 404 | fields url | fields - _*] [search 303 | fields url | fields - _*]
See also
append, appendcols, appendpipe, join, diff
Answers
Have questions? Visit Splunk Answers and see what questions and answers the Splunk community has using the set command.
PREVIOUS sendemail |
NEXT setfields |
This documentation applies to the following versions of Splunk® Enterprise: 6.0, 6.0.1, 6.0.2, 6.0.3, 6.0.4, 6.0.5, 6.0.6, 6.0.7, 6.0.8, 6.0.9, 6.0.10, 6.0.11, 6.0.12, 6.0.13, 6.0.14, 6.0.15, 6.1, 6.1.1, 6.1.2, 6.1.3, 6.1.4, 6.1.5, 6.1.6, 6.1.7, 6.1.8, 6.1.9, 6.1.10, 6.1.11, 6.1.12, 6.1.13, 6.1.14, 6.2.0, 6.2.1, 6.2.2, 6.2.3, 6.2.4, 6.2.5, 6.2.6, 6.2.7, 6.2.8, 6.2.9, 6.2.10, 6.2.11, 6.2.12, 6.2.13, 6.2.14, 6.2.15, 6.3.0, 6.3.1, 6.3.2, 6.3.3, 6.3.4, 6.3.5, 6.3.6, 6.3.7, 6.3.8, 6.3.9, 6.3.10, 6.3.11, 6.3.12, 6.3.13, 6.3.14, 6.4.0, 6.4.1, 6.4.2, 6.4.3, 6.4.4, 6.4.5, 6.4.6, 6.4.7, 6.4.9, 6.4.10, 6.4.11, 6.5.1612 (Splunk Cloud only), 6.5.2, 6.5.3, 6.5.4, 6.5.5, 6.5.6, 6.5.7, 6.5.8, 6.5.9, 6.6.0, 6.6.1, 6.6.2, 6.6.3, 6.6.4, 6.6.5, 6.6.6, 6.6.7, 6.6.8, 6.6.9, 6.6.10, 6.6.11, 6.6.12, 7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.0.4, 7.0.5, 7.0.6, 7.0.7, 7.0.8, 7.0.9, 7.0.10, 7.0.11, 7.0.13, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.1.6, 7.1.7, 7.1.8, 7.1.9, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.2.8, 7.2.9, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 8.0.0, 6.4.8, 6.5.0, 6.5.1, 6.5.10
Comments
The "See Also" section is missing appendpipe.
Woodcock - Thank you for pointing out that the See Also section was missing the appendpipe command. I have added it to that section.