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
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!

Thanks for the Memories: .conf26 Took Learning to New Heights

Thank you, Splunk Community, for making .conf26 in Denver one for the books. From packed Splunk University ...

Best Practices: Splunk auto adjust pipeline queue

When you enable autoAdjustQueue in Splunk, maxSize should be understood as the queue size Splunk starts with ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...