Splunk Search

How can I pair search results from two different queries where only time is different?

plajcsi
Engager

I have a query where I get "STARTED" and "FINISHED" status events for the same methods.
e.g.
index IN (private public) sourcetype in (X Y) log_entry=method_status method=getCusips status=STARTED 
| rename _time as start_time
| table sourcetype method start_time status

| sort start_time

for this query I get more, let's say 3 results where everything is the same for the event, except event _time

also I would like to get "FINISHED" events so the same only with finished
index IN (private public) sourcetype in (X Y) log_entry=method_status method=getCusips status=FINISHED
| rename _time as end_time
| table sourcetype method end_time status 
| sort end_time

I will always get the same number of events for both queries.
Since it is sorted I would need to pair the first started with first finished,  second started with the second finished and so on, and get the duration (end_time - start_time), but how?

So what I would like to see is, let's say if I have 2 started and 2 finished events, and as I mentioned only the time is different(between the 2 started events so I cannot use anything else):

source_typemethodstart_timeend_timeduration
XgetCusips 12164
XgetCusips 18202


I was thinking to iterate on the events somehow and map them the 1st to the 1st, 2nd to 2nd, but no idea if this is even doable.

Hope I have explained it clearly.

0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Since "everything is the same" and you "get the same number of events for both queries" and "it is sorted", you could try using appendcols

index IN (private public) sourcetype in (X Y) log_entry=method_status method=getCusips status=STARTED 
| rename _time as start_time
| table sourcetype method start_time status
| sort start_time
| appendcols
[ search index IN (private public) sourcetype in (X Y) log_entry=method_status method=getCusips status=FINISHED
| rename _time as end_time
| table sourcetype method end_time status 
| sort end_time]
| eval duration=end_time-start_time

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Since "everything is the same" and you "get the same number of events for both queries" and "it is sorted", you could try using appendcols

index IN (private public) sourcetype in (X Y) log_entry=method_status method=getCusips status=STARTED 
| rename _time as start_time
| table sourcetype method start_time status
| sort start_time
| appendcols
[ search index IN (private public) sourcetype in (X Y) log_entry=method_status method=getCusips status=FINISHED
| rename _time as end_time
| table sourcetype method end_time status 
| sort end_time]
| eval duration=end_time-start_time

plajcsi
Engager

Yepp, that works fine, thank you so much for the help! 🙂

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...