Splunk Search

How can I combine two queries based on chronological order?

dukie
New Member

I have two searches and I am trying to join start and stop post based on event name. Problem is event name could be the same so ”stats first(*) as * by Event_same_name” is not working for me.

I have sorted the table based on time, so I know the start and stop is in chronicle and correct order

Table:

Event_same_name     Start_epoch     Stop_epoch
Event               time_A
Event                               time_B
Event               time_C  
Event                               time_D
Event               time_E  
Event                               time_F

Output:

Event_same_name     Start_epoch     Stop_epoch
Event               time_A          time_B                                 
Event               time_C          time_D                
Event               time_E          time_F
Tags (2)
0 Karma
1 Solution

renjith_nair
Legend

@dukie,

Try

"your search to sort events" |eval rowno=1|accum rowno
|streamstats current=f window=1 last(_time) as Start_epoch|where rowno%2==0|rename _time as Stop_epoch|fields - rowno

Start event which does not have an end event is neglected here.

---
What goes around comes around. If it helps, hit it with Karma 🙂

View solution in original post

0 Karma

renjith_nair
Legend

@dukie,

Try

"your search to sort events" |eval rowno=1|accum rowno
|streamstats current=f window=1 last(_time) as Start_epoch|where rowno%2==0|rename _time as Stop_epoch|fields - rowno

Start event which does not have an end event is neglected here.

---
What goes around comes around. If it helps, hit it with Karma 🙂
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 ...