Splunk Search

Add Filter Query if Field Exists

lmattar
Engager

Hi. I already have a Splunk query that we use in a production environment. We are now adding a new field that we'd like to filter on. However, we want to remain backwards compatible with the query so we can still view the data before adding this new field. Here's sort of what I'd like:

Current:

index=prod sourcetype="prod" year="2019" jobId="21766782-c79d-40c3-a9bf-a3b7269ef557"

 

With New Field:

index=prod sourcetype="prod" year="2019" jobId="21766782-c79d-40c3-a9bf-a3b7269ef557" if(exists(type), type="MY_TYPE", "")

 

I know this isn't the right syntax, but essentially I want to filter on that field if it exists in the data. If it doesn't, I want it to exclude it (basically use the old query).

Labels (1)
0 Karma
1 Solution

renjith_nair
Legend

Try

index=prod sourcetype="prod" year="2019" jobId="21766782-c79d-40c3-a9bf-a3b7269ef557" 
|where  (type="MY_TYPE" OR isnull(type))
---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

0 Karma

renjith_nair
Legend

Try

index=prod sourcetype="prod" year="2019" jobId="21766782-c79d-40c3-a9bf-a3b7269ef557" 
|where  (type="MY_TYPE" OR isnull(type))
---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

lmattar
Engager

This worked! Thank you very much!!

0 Karma
Get Updates on the Splunk Community!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...