Splunk Search

How to use the Where clause in my search?

vnguyen46
Contributor

I have index A with fields: username, field1, field2
I have main:sourcetype B with fields: userid, fullname

Trying to search for: username, field1, field2 WHERE username = userid
Any ideas will help.
Thanks,

Tags (2)
0 Karma
1 Solution

aholzer
Motivator

you can use a subsearch to limit the results to those that have a match from your secondary information source.

index=A [| search index=main sourcetype=B | fields userid | rename userid AS username]

This will return only results from index=A where the username is in the list of userid's from index=main sourcetype=B.

Warning: subsearches have a 10k limit in terms of results that can be returned, so if you have more than 10k results in your secondary information source this will not work

Hope this helps

View solution in original post

0 Karma

aholzer
Motivator

you can use a subsearch to limit the results to those that have a match from your secondary information source.

index=A [| search index=main sourcetype=B | fields userid | rename userid AS username]

This will return only results from index=A where the username is in the list of userid's from index=main sourcetype=B.

Warning: subsearches have a 10k limit in terms of results that can be returned, so if you have more than 10k results in your secondary information source this will not work

Hope this helps

0 Karma

vnguyen46
Contributor

It works well. My index main <2000 records.
Thank you.

0 Karma

vnguyen46
Contributor

The key is "userid" in a different index/sourcetype. I meant looking for records in index A for only userid in index/sourcetype B.
index=A OR sourcetype=B
...somewhere I need to add A.username=B.userid
that means only userid in soucetype B will display

0 Karma

burwell
SplunkTrust
SplunkTrust

If you just want to search for a field having a value in the first part of the search leave off the WHERE

0 Karma
Get Updates on the Splunk Community!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...