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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...