Splunk Search

How to join two search using condition if ,case, or where?

Cs80
Loves-to-Learn Lots

Hi there,

I am new to splunk and  struggling to join two searches based on conditions .eg. left join  with field 1 from index2  if field1!=" " otherwise  left join with field 2 from index 2. Field 2 is only present in index 2.and Field 1 is common in 

I  have two spl  giving right result when executing separately . I don't know how to merge both spl based on above condition to get complete result.  Thanks

Labels (1)
0 Karma

Cs80
Loves-to-Learn Lots

I tried using coalesce but no luck.  I am trying to find all domains in our scope  using many different indexes  and multiple joins. I am currently using two separate searches and  both search queries are working fine when executing separately. I want to join both search queries to get complete result. I tried using coalesce with eval Domain in my search where some of  public IP are missing .I want to use Private_IP when Public_IP is not there. Then I plan to Join both queries based on Domain.

| eval Domain= coalesce( Public_IP, Private_IP)  . After using coalesce command  new field Domain showing up  empty space as in Public _IP. In other works new filed Domain is replicating Public_IP .  I also tried using if  with eval bit  no luck.

| eval Domain=if(isnull(Public_IP),Private_IP, Public_IP).

 

0 Karma

PickleRick
SplunkTrust
SplunkTrust

That would meant that you do not have a field named Private_IP in events which do not have Public_IP. Remember that with Splunk case in field names is important.

0 Karma

PickleRick
SplunkTrust
SplunkTrust

As an extension of what @richgalloway already wrote - in Splunk usually join is not the way to go. Try to describe what you have (it's best if you give some examples of the events you have) and what you want to achieve. We'll see what can be done 😉

0 Karma

richgalloway
SplunkTrust
SplunkTrust

There's no such thing as a "conditional join" in Splunk.  The join must always be on the same field(s).  Any conditions must be satisfied before the join is performed.

<<search 1>>
| eval joinField = field1
| join type=left joinField [
  <<search 2>>
  | eval joinField = coalesce(field1, field2)
  ]
---
If this reply helps you, Karma would be appreciated.
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!

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

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...