Splunk Search

Is there a way to populate an "IN (...)" with items from subsearch?

spinnerdog
Explorer

Is there a way to populate the items in an "IN" statement with the results of a sub query?  I've tried several variations.

index=x accountid IN ( [ search index=special_accounts | rename accountid as query ] ) 

Labels (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Since the IN operator is mapped to a series of ORs under the covers, use the OR output produced by the subsearch.

 

index=x accountid [ search index=special_accounts | rename accountid as query | fields query | format ]

 

---
If this reply helps you, Karma would be appreciated.
0 Karma

spinnerdog
Explorer

Okay, thanks.  Was trying to work around using the format command, but maybe there is a way to use it differently.  How can you make the format command produce output like.

[search index=special_accounts | table accountid | format mvsep=AND ]

where the desired output would use != instead of =

(accountid!=xxx AND accountid!=yyy AND ...)

 

Thanks

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Why avoid format?  It produces the same thing that IN does.

You can change OR to AND in format, but there's no way I can find to change = to !=.  However, "(foo!=bar AND foo!=baz)" is not the same as "foo IN (bar, baz)", which is what I thought the OP wanted.

---
If this reply helps you, Karma would be appreciated.
0 Karma

spinnerdog
Explorer

correct, its just the inverse of what the format command produces.  I have a list of valid values and I want the events with invalid values.  Was hoping to use something line NOT IN (...).  But that's not an option and I also can't find a way to change = to "!=".

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Oh!  That's easy!  Just negate the subsearch.

index=x accountid NOT [ search index=special_accounts | rename accountid as query | fields query | format ]

It'll give you NOT (foo=bar OR foo=baz)

---
If this reply helps you, Karma would be appreciated.
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 ...