Splunk Search

Joining 2 sourcetypes by property value

chrisdev
Explorer

Hey all,

I have 2 source types with the following properties

source_1

  • id
  • value

source_2

  • name
  • description

So my events might look similar to:

  • source_1: id=abc-123, value="blah"
  • source_2: name=abc-123, description="some_description"

The values of source_1.id and source_2.name are equal.

Im trying to display the id/name, description and value in a table. I've came up with the following query to do so:

 

index=main sourcetype=source_2
| rename name AS id
| join id [search index=main sourcetype=source_1 id=*]
| table id, value, description

 

Is my query the best way to achieve this? Are there any alternatives?

Labels (1)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

That left join can be implemented with append and stats, as bowesmana recently reminded me.  It is not necessarily more performant, as it all depends on data characteristics, and what other constraints you can place on each search.

Here is one generic idea

 

index=main sourcetype=source_2
| rename name AS id
| append [search index=main sourcetype=source_1 id=*]
| eventstats dc(sourcetype) as sourcecount by id
| where sourcecount == 2
| table asset_id, id, description

 

This is not likely to be performant.  If, on the other hand, asset_id and description are the only fields you care about, you can use stats instead of eventstats.  stats will perform better if your data contains lots of other fields

 

index=main sourcetype=source_2
| rename name AS id
| append [search index=main sourcetype=source_1 id=*]
| stats dc(sourcetype) as sourcecount values(asset_id) as asset_id values(description) as description by id
| where sourcecount == 2
| fields - sourcecount

 

Under the search window, you can open "Job -> Inspect Job" to compare performance.

richgalloway
SplunkTrust
SplunkTrust

Try to avoid joins when possible because they're not efficient commands.  See how this works for you.

index=main (sourcetype=source_2 OR sourcetype=source_1 id=*)
| eval id = coalesce(name, id)
| stats values(*) as * by id
| table asset_id, id, description
---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

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

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...