Splunk Search

Get result from past query result as a parameter

prategup1
New Member

I have two queries which are working fine independently but I want to join those two and get the result in one go. Can you please help how to achieve that.

Logs having session Id :
2016-03-15 09:31:40,083 INFO dsadsadjsakldjsalkdjaskldj **Test@123456789*
(SessionId : 123456789 )*

Query1 : index=test "Search String1" | rex "Test@(?<SessionId>[^<]+)" | table SessionId :- From This we are extracting all the session id's.

Now we have to extract another value (IDNO) by checking logs for whole session using session id which is common in both queries.

Log having both SessionId and IDNO :
2016-03-15 09:31:40,027 INFO sadasdjadjhasjkdhsakdjshakdjhsakdja Test@123456789
IDNO 747711680

Query2 : index=test "Search String2" SessionId | rex "IDNO (?[^<]+)" | table ID

We have to print all ID values for corresponding sessionid values in last 24 hours.

Thanks in advance

Tags (2)
0 Karma

somesoni2
Revered Legend

Since, the session id is not originally extracted (and based on your sample 2nd search), you want to put the SessionId string value on to the search. Try something like this

index=test "Search String2" [search index=test "Search String1" | rex "Test@(?<SessionId>[^<]+)" | stats count by SessionId | table SessionId | rename SessionId as search ] | rex "IDNO (?<ID>[^<]+)" | stats count by ID
0 Karma

DMohn
Motivator

Subsearches are your key to success here:

 index=test "Search String2" [search index=test "Search String1" | rex "Test@(?<SessionId>[^<]+)" | table SessionId]  | rex "IDNO (?[^<]+)" | table ID
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...