Splunk Search

Join a search by field across indexes

aarichow
Explorer

I have two different indexes, with the common field being username.

One index that contains phishing history data. index="phish"
One index that contains a list of usernames. index="poorpass"

I'd like to join both indexes, and match them by username. So I'll have a list of users that are in both indexes.

index="phish" status="Clicked Link" 
| eval username=email 
| rex field=username mode=sed "s/@\S+//g" 
| join host 
    [search index="poorpass" group="username"]
| table username

My search goes through with no errors, but no events are returned.

Tags (1)
1 Solution

MuS
Legend

HI aarichow,

give this a try:

( index="phish" status="Clicked Link" ) OR ( index="poorpass" group="username" )
| rex field=email mode=sed "s/@\S+//g" 
| eval username=case(isnotnull(email), email, isnotnull(username), username, 1=1, "unknown")
| stats values(*) AS * by username, _time

The eval will use either email, username, or if neither is available fill the value as unknown

Hope this helps ...

cheers, MuS

View solution in original post

woodcock
Esteemed Legend

Like this:

(index="phish" status="Clicked Link") OR (index="poorpass" group="username")
| eval username=if(index="phish", email, null())
| rex field=username mode=sed "s/@\S+//g" 
| stats values(*) AS * BY host

MuS
Legend

HI aarichow,

give this a try:

( index="phish" status="Clicked Link" ) OR ( index="poorpass" group="username" )
| rex field=email mode=sed "s/@\S+//g" 
| eval username=case(isnotnull(email), email, isnotnull(username), username, 1=1, "unknown")
| stats values(*) AS * by username, _time

The eval will use either email, username, or if neither is available fill the value as unknown

Hope this helps ...

cheers, MuS

aarichow
Explorer

I ran the search, this just returns all the users that have the status="clicked link", it doesn't match it to the field in poorpass.

0 Karma

MuS
Legend

Can you please provide at least two anonymised events for each criteria? Thanks

cheers, MuS

0 Karma

aarichow
Explorer

To clarify, the reason I'm creating the field called username is because it's not an existing field in my index. There is a field in the index, phish, called email, which is the same as username in this case, so I just strip the email at the @ sign, giving me the username.

I'm then trying to match this field to a existing field in the index poorpass.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

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 ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...