Splunk Search

How do I search for events that match a regex OR have Key?

splunkqy
Explorer

Say I have an event in the form:

{
    "a": {"b": "c"},
    "d": "e"
 }

I want to include the event if "c" matches a regex or if the value "e" is not null or empty.

How do I write a query for this? As far as I know, you can only find events matching a regex by using | regex <regular expression>. Is there a way to do this like (d != "" AND d != null) OR ( a.b AND | regex <regular expression>)?

0 Karma
1 Solution

chrisyounger
SplunkTrust
SplunkTrust

I would recommend you use the rex command : |rex field=WHATEVER "(?<my_new_field>MATCH_TO_CHECK)"

This will simplify your conditional logic becuase you can just do:

eval includeRecord = if((d != "" AND d != null) OR ( a.b AND isnotnull(my_new_field)), "true", "false") | search includeRecord=true

Hope you can understand my untested code 🙂

View solution in original post

0 Karma

chrisyounger
SplunkTrust
SplunkTrust

I would recommend you use the rex command : |rex field=WHATEVER "(?<my_new_field>MATCH_TO_CHECK)"

This will simplify your conditional logic becuase you can just do:

eval includeRecord = if((d != "" AND d != null) OR ( a.b AND isnotnull(my_new_field)), "true", "false") | search includeRecord=true

Hope you can understand my untested code 🙂

0 Karma
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...