Splunk Search

can I aggregate two queries

rakesh_498115
Motivator

I Have Two sourcetypes defined . i need to write a query integrating the two sourcetypes and should get a single result.

i.e for example
Sourcetype="X" | (some logic )|stats avg(duration) as Avgresponsetime1

Sourcetype="Y" | (some logic ) |stats avg(duration) as Avgresponsetime2

Now i need a single Query which gives me the ouput as avgresponsetime of the avg from the previous two reponsetimes..

i have tried like this..but didnt work..

(Sourcetype="X" | (some logic )|stats avg(duration) as Avgresponsetime1) OR ( Sourcetype="Y" | (some logic ) |stats avg(duration) as Avgresponsetime2 ) | eval responsetime=avgresponsetime1+avgresponsetime2 | table responsetime

Please help me on this asap..thanx

0 Karma
1 Solution

Ayn
Legend

You can't put an OR between them because by the time you get to the OR you've already "left" the initial search command and piped it to a number of other commands.

You could use append for getting results from the two searches and then run stats on all results:

 Sourcetype="X" | (some logic )| append [search Sourcetype="Y" | (some logic )] | stats avg(duration) as responsetime

View solution in original post

Ayn
Legend

You can't put an OR between them because by the time you get to the OR you've already "left" the initial search command and piped it to a number of other commands.

You could use append for getting results from the two searches and then run stats on all results:

 Sourcetype="X" | (some logic )| append [search Sourcetype="Y" | (some logic )] | stats avg(duration) as responsetime
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...