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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...