Splunk Search

Why is my join not working?

leftinnerouter
Explorer

Basically my query should search an index for an ip in the last 4 hours and return 1 event.

Then it should left join on IP to a second index and search for results over the last 7 days.

The IP i am searching exists in both indexes.

Why are no results being returned?

earliest=-4h latest=now() index=data1 Source_Network_Address=10.1.1.1
| head 1
| rename Source_Network Address as IP
| join type=left IP max=5
[search earliest=-7d latest=now() index=data2
| fields IP, DNS]
| table index, _time, IP, DNS
Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

First check:

Two searches - do they return data.

earliest=-4h latest=now() index=data1 Source_Network_Address=10.1.1.1
| head 1
| rename Source_Network Address as IP

AND

earliest=-7d latest=now() index=data2 IP=10.1.1.1
| table index, _time, IP, DNS

Secondly, don't use join - if you're looking for a single IP in both 'index=data1' in last 4 hours   AND 'index=data2' in last 7 days you could use a simple OR search

(earliest=-4h latest=now() index=data1 Source_Network_Address=10.1.1.1) OR 
(earliest=-7d latest=now() index=data2 IP=10.1.1.1)
| rename Source_Network Address as IP
| table index, _time, IP, DNS

you can then control which of the returned entries you are interested in.

Note that if you DO you join, then always join on the smaller data set, otherwise you are likely to come up against limits. As @gcusello says,  join is rarely the way to solve a Splunk query - there are almost always better ways to write the query, typically using 'stats' to join things together, e.g. you could end the above second query with

| stats values(*) as * by IP

 

View solution in original post

0 Karma

bowesmana
SplunkTrust
SplunkTrust

First check:

Two searches - do they return data.

earliest=-4h latest=now() index=data1 Source_Network_Address=10.1.1.1
| head 1
| rename Source_Network Address as IP

AND

earliest=-7d latest=now() index=data2 IP=10.1.1.1
| table index, _time, IP, DNS

Secondly, don't use join - if you're looking for a single IP in both 'index=data1' in last 4 hours   AND 'index=data2' in last 7 days you could use a simple OR search

(earliest=-4h latest=now() index=data1 Source_Network_Address=10.1.1.1) OR 
(earliest=-7d latest=now() index=data2 IP=10.1.1.1)
| rename Source_Network Address as IP
| table index, _time, IP, DNS

you can then control which of the returned entries you are interested in.

Note that if you DO you join, then always join on the smaller data set, otherwise you are likely to come up against limits. As @gcusello says,  join is rarely the way to solve a Splunk query - there are almost always better ways to write the query, typically using 'stats' to join things together, e.g. you could end the above second query with

| stats values(*) as * by IP

 

0 Karma

leftinnerouter
Explorer

@bowesmana  @gcusello thank you for your help. I've reverted to a simple search.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @leftinnerouter,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

leftinnerouter
Explorer

Yes  I would like to check if the IP from the main search in 4 hours was present in the previous 7 days.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @leftinnerouter,

how many results have you running the subsearch by itself? probably more than 50,000.

There's a limit of 50,000 results in subsearches, in addition the join command is very slow.

You are in the usual error of people coming from SQL: Splunk isn't a DB and you should use join only when you haven't any other solution.

in your case, I suppose  that you want to check if the IP from the main search in 4 hours was present in the previous 7 days, is it correct?

If this is your requirement, please, try this approach:

index=data2 earliest=-7d latest=now() [ search index=data1 Source_Network_Address=10.1.1.1 earliest=-4h latest=now() | head 1 | rename Source_Network Address as IP | fields IP ]
| table index _time IP DNS

Ciao.

Giuseppe

0 Karma

leftinnerouter
Explorer

Sorry for the late response.

There are less than 50,000 results and I have attempted adding a limit as suggested. 

Unfortunately this is still not working for me as expected.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...