Splunk Search

How to find records where a field's value doesn't exist in a subsearch?

saqib99
New Member

I have the following two searches:

1) earliest=-4h latest=now index="main" field1="somethingA"
2) earliest=-4h latest=now index="main" field2="somethingB"

All records contain a field name field3.

I want to find all the records that are in query #1 but whose field3 is not found in any records in query #2.

How can I do it?

0 Karma

saqib99
New Member

This worked:

> earliest=-4h latest=now index="main" field1="somethingA" NOT [search earliest=-4h latest=now index="main" field2="somethingB" | fields + field3]
0 Karma

to4kawa
Ultra Champion

I see, please accept your answer and close.

0 Karma

to4kawa
Ultra Champion
index=main (field1="somethingA" OR field2="somethingB" ) earliest=-4h latest=now 
| streamstats window=1 values(eval(if(field1="somethingA" AND NOT field2="somethingB","flag",NULL))) as field3_exc_field2_inc_field1
| where field3_exc_field2_inc_field1="flag"

hi, @saqib99
how about this?

0 Karma

saqib99
New Member

That didn't work. But the answer shown below did.

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...