Splunk Search

Retrieving results where field matches a list of fields in another search

ericp56
Explorer

Hello,

Let me provide an explanation of what I am trying to do:

Here are some log entries. I put the field names above the entries, for this illustration:

session page result
1 A OK
1 B OK
1 C OK
2 A OK
2 C OK

I want my search return all entries for a session which contain the field "page" equal to B.

So based on the above entries, my result set would be

1 A OK
1 B OK
1 C OK

I will export the results so I can read through the logs, which may be 500-2000 lines per session.

A transaction might be OK - * | sort by session, _time | transaction session | page=A

but then I have all the events merged together like so:
1 A OK 1 B OK 1 C OK

The export is fine to read through

However, if I want to do further field analysis, how can I get the results to be per event, instead of unioned together per the transaction?

Tags (1)
0 Karma
1 Solution

sowings
Splunk Employee
Splunk Employee

Start with a search to find the page=B part:

index=yourindex sourcetype=logtype page=B

Tell Splunk you want the session ID:

index=yourindex sourcetype=logtype page=B | fields session

Then ask Splunk to take the results from this set and use them to seed another search. This is the "subsearch" mechanism--easy to spot when you see [ ].

index=yourindex sourcetype=logtype [ index=yourindex sourcetype=logtype page=B | fields session ]

This will result in a search term like: ( ( session=1 ) OR ( session=2 ) OR ( session=7) )

After that, you can do stats or transaction or whatever you like to get the events. Note that as it stands, the search will give you as many events per session, by as many matching sessions there are. Stats or some other command can help distill some of the results for you.

View solution in original post

sowings
Splunk Employee
Splunk Employee

Start with a search to find the page=B part:

index=yourindex sourcetype=logtype page=B

Tell Splunk you want the session ID:

index=yourindex sourcetype=logtype page=B | fields session

Then ask Splunk to take the results from this set and use them to seed another search. This is the "subsearch" mechanism--easy to spot when you see [ ].

index=yourindex sourcetype=logtype [ index=yourindex sourcetype=logtype page=B | fields session ]

This will result in a search term like: ( ( session=1 ) OR ( session=2 ) OR ( session=7) )

After that, you can do stats or transaction or whatever you like to get the events. Note that as it stands, the search will give you as many events per session, by as many matching sessions there are. Stats or some other command can help distill some of the results for you.

ericp56
Explorer

Thanks! That's exactly what I needed.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...