Splunk Search

Combine results from 2 searches with a common field

lohit
Path Finder

Hi all ,

i am trying to merge my results from 2 searches running over different indexes that have a common field "url".

index ="abc"| join url [search index="xyz" | eval url=uri | fields + url, a,b,c ]

i have used the eval command because in index "xyz" field name is uri but the values are same. What i am looking of is

  1. To merge these 2 results and output uncommon fields from index "abc" and index "xyz along with "url".

Please help

Tags (1)
0 Karma

MuS
Legend

Hi lohit,

you should be able to use something like this:

index=abc OR index=xyz | eval url=coalesce(url, uri) | stats count by url, a, b, c

The eval coalesce will take care that you have a url field for each event fron any index.

Also take a look at this answer for more details http://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-joi...

Hope this helps ...

cheers, MuS

0 Karma

lohit
Path Finder

Hi MuS ,

i have match events containing url from index "xyz" which have same url in index "abc" and not from either of them.

0 Karma

MuS
Legend

Okay, then you should be able to simply use a index=abc OR index=xyz | stats by url if you have this field in both indexes....but you wrote in your question that you have not, that's why you used the eval.....

0 Karma

lohit
Path Finder

ok let me explain again.

in index "abc" i have field url, x,y
in index "xyz" i have field uri,a,b
now this uri and url are same fields across indexes. my concern is that how can i get something like this without join in table

col1 col2 col3 col4 col5
url(both index) x y a b

0 Karma

MuS
Legend

Understood, try my first search and to add a b x y use streamstats like in the answer I provided the link 😉 Or do it only by using streamstats .... like

 index=abc OR index=xyz | streamstats values(a) AS a, values(b) AS b .... 
0 Karma

lohit
Path Finder

Ok i have written the below query

index="abc" |eval agt=cs_us| join url [ search index="xyz" | eval url=uri |stats values(a) as a,values(s) as s, by url | fields a,s,url] | stats values(agt) values(a),values(s) by url

how can i better write this query ?

0 Karma

MuS
Legend

try this:

index="abc" OR index=xyz |eval agt=cs_us | eval url=uri | stats values(a) AS a,values(s) AS s, values(agt) AS atg by url 
0 Karma

lohit
Path Finder

it is not returning any results !!

0 Karma

MuS
Legend

Since I don't have any of your events, I cannot test it. But I did show your the direction to go. Read the linked answer and use the provided searches to try it yourself. Afterwards adopt the searches to your real world events.

0 Karma

lohit
Path Finder

ok thanks MuS

0 Karma

lohit
Path Finder

MuS, if i run your last suggestion,it is
giving fields from only one index.

0 Karma

MuS
Legend

I just did a copy paste of your provided search where you asked how can i better write this query ? yesterday

0 Karma

lohit
Path Finder

using join , my query is very slow since both the index is very noisy. Any help from your side ?

0 Karma

lohit
Path Finder

Yes it is quite strange. my join query is working fine but with stats only it is returning fields from one index.

0 Karma

lohit
Path Finder

index=abc OR index=xyz| eval url=uri | stats values(a),values(x) by url

values(a) is from index=abc and is coming
values(x) is from index=xyz and is not coming.

0 Karma

lohit
Path Finder

Also in the output i have to display fields of both indexes. i have done it using join but it very slow. any faster way of doing it.

0 Karma

lohit
Path Finder

solved it
myself

0 Karma
Get Updates on the Splunk Community!

Celebrating Fast Lane: 2025 Authorized Learning Partner of the Year

At .conf25, Splunk proudly recognized Fast Lane as the 2025 Authorized Learning Partner of the Year. This ...

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...