Splunk Search

What is the order that executes in query when I use both AND, OR in splunk query?

pavanae
Builder

I have two different queries like below

Query 1 :-

field_1!="A" AND field_2="B" OR field_1!="A" AND field_2="C" OR field_1!="A" AND field_2="D" OR field_1!="A" AND field_2="E"  

Query 2 :-

field_1!="A" AND (field_2="B" OR field_2="C" OR field_2="D" OR field_2="E" )

In my view both the queries should give the same result but it's giving me the different result. What's the difference between both the queries and what's the actual order splunk executes?

0 Karma
1 Solution

somesoni2
Revered Legend

Your query 1 is hochpoch because of no clear distinction of the grouping of AND conditions and due to order in which the logical operators are executed (see here) they're not doing what you want to do, which is query 2. Below two query should give you same result.

Reformatted query 1:

(field_1!="A" AND field_2="B") OR (field_1!="A" AND field_2="C") OR (field_1!="A" AND field_2="D") OR (field_1!="A" AND field_2="E" ) 

Query 2 :-

 field_1!="A" AND (field_2="B" OR field_2="C" OR field_2="D" OR field_2="E" )

View solution in original post

0 Karma

somesoni2
Revered Legend

Your query 1 is hochpoch because of no clear distinction of the grouping of AND conditions and due to order in which the logical operators are executed (see here) they're not doing what you want to do, which is query 2. Below two query should give you same result.

Reformatted query 1:

(field_1!="A" AND field_2="B") OR (field_1!="A" AND field_2="C") OR (field_1!="A" AND field_2="D") OR (field_1!="A" AND field_2="E" ) 

Query 2 :-

 field_1!="A" AND (field_2="B" OR field_2="C" OR field_2="D" OR field_2="E" )
0 Karma

pavanae
Builder

Cool thanks @somesoni2. That makes sense now. PLease post the same as a answer. I am going to accept that. Thanks again.

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 ...