Splunk Search

Replace join with stats to merge events based on common field

eddiet
Explorer

My datasets are much larger but these represent the crux of my hurdle

sourcetype=sale_by
fields: sid, user

sourcetype=sale_made
fields: sid, amount

Where: sale_made.sid = sale_by.sid

I have this search that works:

sourcetype=sale_by  | join sid [ search sourcetype=sale_made ] | stats sum(amount)  by user

Can this be done more efficiently with stats?

1 Solution

MuS
SplunkTrust
SplunkTrust

Hi eddiet,

Sure, try this:

 sourcetype=sale_by OR sourcetype=sale_made 
| stats values(user) AS user sum(amount) AS amount by sid 
| stats values(amount) AS amount by user

This is not tested and also depends on your events and the expected result, but it should give you an idea how it can be done.
You can read this answer https://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-jo... to learn more about this topic.

Hope this helps ...

cheers, MuS

View solution in original post

woodcock
Esteemed Legend

Try this:

sourcetype=sale_by OR sourcetype=sale_made
| stats values(user) AS user sum(amount) as amount BY sid
| stats sum(amount) as amount BY user

MuS
SplunkTrust
SplunkTrust

Hi eddiet,

Sure, try this:

 sourcetype=sale_by OR sourcetype=sale_made 
| stats values(user) AS user sum(amount) AS amount by sid 
| stats values(amount) AS amount by user

This is not tested and also depends on your events and the expected result, but it should give you an idea how it can be done.
You can read this answer https://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-jo... to learn more about this topic.

Hope this helps ...

cheers, MuS

woodcock
Esteemed Legend

Wow, almost a jinx!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...