Splunk Search

How to cluster in subsearch based on EventCode results returned from main search?

jyim89
New Member

I essentially want to do something like this:

host="*mas*" sourcetype="WinEventLog:Application" AND (Type=Error OR Type=Warning) | foreach EventCode [ search host="*mas*" sourcetype="WinEventLog:Application" EventCode='<<FIELD>>' | cluster ]

However this an error saying "Error in 'foreach' command: Search pipeline may not contain non-streaming commands" It basically doesn't like the cluster command as part of the foreach.

To clarify, I want to cluster based on the EventCodes of the results returned from the initial search. I don't want to cluster on the whole of the initial search itself. Is there an easy way of doing this?

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try this

host="*mas*" sourcetype="WinEventLog:Application" [search host="*mas*" sourcetype="WinEventLog:Application" AND (Type=Error OR Type=Warning) | stats count by EventCode | table EventCode] | cluster

The subsearch gets all the EventCodes with Type=Error OR Type=Warning and is passed to main search.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...