Splunk Search

How to return the latest events where one field is equal to a certain value without using subsearches?

DEngineer1
New Member

Hi Guys,

I have got a problem which I need to return results when 1 field is of a certain value BUT only after a certain event.

Serial_No   Complete
     7         0
     5         0
     4         0
     3         1
     2         1
     1         0

In the case above, I only need to return rows where complete==0 BUT only considering rows that are after complete==1 (so the row where Serial_No==1 is not considered)

In the example above the results will be:

Serial_No   Complete
     7         0
     5         0
     4         0

Any possibility to get the result without any subsearches?
Thanks!

0 Karma
1 Solution

somesoni2
Revered Legend

Try like this

your current search giving Serial_No Complete | sort 0 Serial_No | streamstats sum(Complete) as temp | where temp>0

View solution in original post

0 Karma

somesoni2
Revered Legend

Try like this

your current search giving Serial_No Complete | sort 0 Serial_No | streamstats sum(Complete) as temp | where temp>0
0 Karma

DEngineer1
New Member

Hey thanks for the recommendation, streamstats really give me the "light bulb"

I was thinking this might work:

"search"| sort + Serial | streamstats window=2 global=f current=t first(complete) as next_com, first(serial) as next_serial | fields serial, complete, next_serial, next_com | eval test=if(complete > next_com, serial, 0) | fields serial, complete, test | eventstats max(test) as m_test | where complete == 0 | where (serial > m_test)

However I do not know is this an efficient search...

Comparing to using sub-search, will this be a faster search?

0 Karma

somesoni2
Revered Legend

The efficiency will depend upon the amount of processing to be done. Your search is doing extra stuff so it might be slower than my query. If your query is working for you, just try like this

 "search"| sort + Serial | streamstats window=2 global=f current=t first(complete) as next_com, first(serial) as next_serial | fields serial, complete, next_serial, next_com | eval test=if(complete > next_com, serial, 0) | eventstats max(test) as m_test | where complete == 0 AND (serial > m_test)
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...