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
Get Updates on the Splunk Community!

Splunk Observability Cloud’s AI Assistant in Action Series: Analyzing and ...

This is the second post in our Splunk Observability Cloud’s AI Assistant in Action series, in which we look at ...

Elevate Your Organization with Splunk’s Next Platform Evolution

 Thursday, July 10, 2025  |  11AM PDT / 2PM EDT Whether you're managing complex deployments or looking to ...

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...