Splunk Search

How to combine multiple search

msg4sunil
Path Finder

How do combine the below 2 searches into one?

1. * orderid|stats count by id

returns something like 

2022-03-21T00:10:16,999Z ...INFO [thread_id=12349, id=VU53ZQCTTMLPG, .....
2022-03-21T00:10:16,995Z....INFO [thread_id=549, id=F2PAC6ITNX6O3,

2. Based on the above response, I need to query as below after fetching the "id".  Note, "id's would vary for different orderid and the number of "id"'s would also vary 

id IN ("VU53ZQCTTMLPG","F2PAC6ITNX6O3")

 

Thank you

0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

@msg4sunil 

index=* [
  search index=* "985be6370637" 
  | stats count by id
  | fields id
]

It is not good practice to use index=* - admins do not like users who cast a wide search net - always be as specific as possible when making your search - particularly in this case, you are making two searches.

 

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

There are a number of ways to do this, with subsearches, joins or aggregations, but it's not easy to give you an absolute solution.

The most obvious example from your description is the subsearch, which would be something like

Your second search [ 
  search your first search
  | stats count by id | fields id
]

which would pass the list of ids in the subsearch to the outer search which is effectively doing 

(id1 OR id=2 OR id=3..)

as part of the outer search

You can use other techniques, such as searching for all the data in a single search and then manipulating it with eval/stats to get to your desired output, but need more info on that.

join command is an option, but should rarely be the first choice, as 'join' has limitations and is not really the way to do this sort of task in Splunk world

 

0 Karma

msg4sunil
Path Finder

@bowesmana , can you please give one example?  The below doesnt work.

index=* id IN [index=* "985be6370637"| fields id]

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@msg4sunil 

index=* [
  search index=* "985be6370637" 
  | stats count by id
  | fields id
]

It is not good practice to use index=* - admins do not like users who cast a wide search net - always be as specific as possible when making your search - particularly in this case, you are making two searches.

 

msg4sunil
Path Finder

Thank you very much @bowesmana for timely help.  Sure, will make the index name as explicit instead of using *.

Thanks again.

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!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Enhance Security Operations with Automated Threat Analysis in the Splunk EcosystemAre you leveraging ...

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, ...