Splunk Search

join only with the first row

rafadvega
Path Finder

Hi,

I need to join two searchs. For example:

Example 1:

 

| inputlookup join_example1.csv

 

countryproductdaystock
Spainapples10/10/202225
Franceapples10/10/202222
Spaingrapes10/10/202230
Francegrapes10/10/202228
Spainapples10/10/202125
Franceapples10/10/202122
Spaingrapes10/10/202130
Francegrapes10/10/202128

 

Example 2:

 

| inputlookup join_example2.csv

 

dayproductrequested
10/10/2022apples90
10/10/2021apples110
10/10/2022grapes100
10/10/2021grapes110


If I join bot searchs:

 

| inputlookup join_example1.csv
| join product, day
    [| inputlookup join_example2.csv]
| table product day country stock requested

 

The result is:

productdaycountrystockrequested
apples10/10/2022Spain2590
apples10/10/2022France2290
grapes10/10/2022Spain30100
grapes10/10/2022France28100
apples10/10/2021Spain25110
apples10/10/2021France22110
grapes10/10/2021Spain30110
grapes10/10/2021France28110

 

But I need the sub search merges only with the first result like this (only in one country):

productdaycountrystockrequested
apples10/10/2022Spain2590
apples10/10/2022France220
grapes10/10/2022Spain30100
grapes10/10/2022France280
apples10/10/2021Spain25110
apples10/10/2021France220
grapes10/10/2021Spain30110
grapes10/10/2021France280

 

That is only a example, I need only merge subsearchs results once. Anyone knows a solution for this?

Thanks!!!

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

You can add this to the end of your example search

| streamstats c by product day
| eval requested=if(c=1,requested,0)
| fields - c

which simply does a count by product and day and then sets requested to 0 if the count value is not 1

Not sure if this will give you a general solution though.

 

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

You can add this to the end of your example search

| streamstats c by product day
| eval requested=if(c=1,requested,0)
| fields - c

which simply does a count by product and day and then sets requested to 0 if the count value is not 1

Not sure if this will give you a general solution though.

 

rafadvega
Path Finder

That is a perfect solution. Thank you very much!

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...