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, say 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:

That search is equivalent to the SQL "NOT IN" functionality:


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

Example

To identify the IP address of the top customer at Buttercup Games with the most purchases, you could run the following search:

Then, you could search the customer's purchase history by running the following search on the customer's IP address, which is 87.194.216.51:

But, what if the next time you run this search, someone else is the top customer? You would have to run the first search again to find out the new top customer's IP address and then rewrite the second search with that new IP address. Instead of going to all of that trouble, you could get the same results by using a subsearch to correlate the events with the IP address and pass the top customer's IP address to the main search every time you run the search:

The search results look something like this: