Splunk Cloud

Search Manual

Download manual as PDF

Download topic as PDF

Use subsearch to correlate events

A subsearch takes the results from one search and uses the results in another search. This enables sequential state-like data analysis. You can use subsearches to correlate data and evaluate events in the context of the whole event set, including data across different indexes or Splunk Enterprise servers in a distributed environment.

For example, you have two or more indexes for different application logs. The event data from these logs share at least one common field. You can use the values of this field to search for events in one index based on a value that is not in another index:

sourcetype=some_sourcetype NOT [search sourcetype=another_sourcetype | fields field_val]

Note: This is equivalent to the SQL "NOT IN" functionality:

SELECT * from some_table
WHERE field_value
NOT IN (SELECT field_value FROM another_table)

About subsearches
Change the format of subsearch results

This documentation applies to the following versions of Splunk Cloud: 7.0.8, 8.0.2001, 7.0.11, 7.1.3, 7.1.6, 7.0.13, 7.2.3, 7.2.4, 7.2.6, 7.2.7, 7.2.8, 7.2.9, 8.0.0, 8.0.1


You probably want to use stats for large datasets since if the subsearch goes over the 10k limit (or whatever yours is set to) you can silently get incorrect results.

sourcetype=some_sourcetype NOT [search sourcetype=another_sourcetype | stats values(field_val) as field_val]


June 24, 2019

Thanks for sharing this. The purpose of this example is to show a basic SQL example so that everyone will understand how the SQL equates to the SPL.

Lstewart splunk, Splunker
February 20, 2019

The SQL comparison code snippet should also include the other (faster) syntax to perform this query that people may be searching for - I know I was:

SELECT * from some_table some
WHERE NOT EXISTS (SELECT NULL FROM another_table another where some.field_value = another.field_value)

January 4, 2019

The WHERE command supports two ways to use the IN function:

...| where in(field,"value1","value2", ...)

...| where field in("value1","value2", ...)

For examples, see the documentation for the IN function here

Lstewart splunk, Splunker
September 5, 2018

Is there an example of how to do an "IN" statement?

August 24, 2018

Was this documentation topic helpful?

Enter your email address, and someone from the documentation team will respond to you:

Please provide your comments here. Ask a question or make a suggestion.

You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters