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!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...