Splunk Search

How to search ForEach value in table

dipendrapokhare
New Member

I would like to search for each value in an extracted field.

My intial query is as follow:

 

index=moneta-pro "IPN Post API  execution started for the orderRefNo" AND "printOs" | rex field=_raw "(?ms)^(?:[^ \\n]* ){9}(?P<orderId>\\d+)" offset_field=_extracted_fields_boundsd_fields_bounds | table orderId | dedup orderId

 

which returns following:

orderId.PNG

Now I'd like to use each value in OrderId and use it in search and append to the above table. For example, check the status of the order. Individual query should look like.

 

index=* " Received response status code as 200 and the message body as" AND orderId=<<each dynamic value from above table>>

 

 

Labels (2)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

Make the first search a subsearch to the second, i.e.

index=* " Received response status code as 200 and the message body as" [ 
  search index=moneta-pro "IPN Post API  execution started for the orderRefNo" AND "printOs" 
  | rex field=_raw "(?ms)^(?:[^ \\n]* ){9}(?P<orderId>\\d+)" offset_field=_extracted_fields_boundsd_fields_bounds 
  | fields orderId
  | dedup orderId
]

Note the use of fields, not table (fields is more efficient in that it can run on the indexer, whereas table will always run on the search head.

 

0 Karma

PickleRick
SplunkTrust
SplunkTrust

In general, your remark is of course correct and hundred percent valid. But in this case I suppose it doesn't make much of a difference since the subsearch results have to be returned to the search-head initiating the search so it can compose the main search with the subsearch results to have a full search for dispatching to search peers.

0 Karma

bowesmana
SplunkTrust
SplunkTrust

It makes a difference in that the original ordering was table + dedup, hence the duplicates would be sent to the SH before being deduped.

I don't know how splunk manages the distribution of multiple searches and whether it has to dispatch each search separately - I've never delved into that too deeply

0 Karma

PickleRick
SplunkTrust
SplunkTrust

Here you are right. I rarely use dedup as such (I'm mostly a "stats values" kinda guy ;-)). You could change the order of commands (dedup | table) but then again fields | dedup is more elegant, I agree.

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Agreed on dedup! It seems somewhat nondeterministic. Makes more sense to use stats

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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...