Splunk Search

How to combine two different searches?

mgrosholz
Path Finder

I am looking to grab the data that fall under two completely different searches.

I have these two searches.

index="A" 
| iplocation src 
| search Country!="country1" status=200
| bucket _time span=1m
| stats count by _time, usr1
| where count > 25

AND

sourcetype="B" 
| bucket _time span=1m
| stats count by _time, usr2
| where count > 25

I want to combine them. Here is what I have so far but it doesn't pull up the data.

index="A" OR sourcetype="B" 
| eval id=case(index="A", "usr1", sourcetype="B", "usr2")
| iplocation src 
| search Country!="country1" status=200
| bucket _time span=1m
| stats count by _time, id
| where count > 25

sourcetype="B" does not contain iplocation or country information. This, I believe, is the issue.

I have tried subsearches, join, append, etc...
Any advise is appreciated.

Tags (2)
0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try

 index="A" OR sourcetype="B" status=200
 | eval id=case(index="A", "usr1", sourcetype="B", "usr2")
 | eventstats values(src) as src1 by id | eval src=coalesce(src,src1)
 | iplocation src 
 | search Country!="country1" 
 | bucket _time span=1m
 | stats count by _time, id
 | where count > 25

View solution in original post

somesoni2
Revered Legend

Give this a try

 index="A" OR sourcetype="B" status=200
 | eval id=case(index="A", "usr1", sourcetype="B", "usr2")
 | eventstats values(src) as src1 by id | eval src=coalesce(src,src1)
 | iplocation src 
 | search Country!="country1" 
 | bucket _time span=1m
 | stats count by _time, id
 | where count > 25

mgrosholz
Path Finder

Awesome. It worked. Can you explain why?

0 Karma

somesoni2
Revered Legend

The eventstats was the trick. After | eval id=case(, you'll a common field between both index=A and sourcetype=B. Using this common field, the eventstats added the src to events in sourcetype=B where it was not earlier. After that since src was available in all events now, iplocation and Country based filter worked.

0 Karma

mgrosholz
Path Finder

Ahhh. Makes sense now. Thank you.

0 Karma
Get Updates on the Splunk Community!

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...