Splunk Search

Joining data from same index on single field value and multifield field

MarekKrzak
Observer

Hi I'm trying to join data from same index but with different marker field and multiple values in second index. Example of rows:

 

TS=06/22/2021 08:50:39:390|Type=A|Ids=550
TS=06/22/2021 08:51:39:390|Type=B|Ids=495,550,698


What I want is merge record Type=A with Record Type=B and get how much time passed (so TS from TypeB - TS from TypeA). Basically records with Type=A will always have one Ids, and with Type=B can have 1 or more Ids.

 

Any ideas what could be the best? selfjoin in this case is not possible as the Type=B is multivalve field .

Labels (1)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@MarekKrzak 

Can you please try this?

YOUR_SEARCH | extract pairdelim="|" kvdelim="=" 
| search Type="A"
| join Type Ids [YOUR_SEARCH | extract pairdelim="|" kvdelim="=" | search Type="B"
| eval Ids=split(Ids,",") | eval Type="A" | rename TS as TS1 
| mvexpand Ids] 
| eval "Time Passed (In Sec)"= round(strptime(TS1,"%m/%d/%Y %H:%M:%S.%3N") - strptime(TS,"%m/%d/%Y %H:%M:%S.%3N")),"Time Passed"=tostring('Run Time (In Sec)',"duration")

 

My Sample Search :

 

| makeresults | eval raw="TS=06/22/2021 08:50:39:390|Type=A|Ids=550&&TS=06/22/2021 08:51:39:390|Type=B|Ids=495,550,698" | eval raw=split(raw,"&&") 
| mvexpand raw | rename raw as _raw | extract pairdelim="|" kvdelim="=" 
| search Type="A"
| join Type Ids [| makeresults | eval raw="TS=06/22/2021 08:50:39:390|Type=A|Ids=550&&TS=06/22/2021 08:51:39:390|Type=B|Ids=495,550,698" | eval raw=split(raw,"&&") 
| mvexpand raw | rename raw as _raw | extract pairdelim="|" kvdelim="=" | search Type="B"
| eval Ids=split(Ids,",") | eval Type="A" | rename TS as TS1 
| mvexpand Ids] 
| eval "Time Passed (In Sec)"= round(strptime(TS1,"%m/%d/%Y %H:%M:%S.%3N") - strptime(TS,"%m/%d/%Y %H:%M:%S.%3N")),"Time Passed"=tostring('Run Time (In Sec)',"duration")

 

Screenshot 2021-06-22 at 10.27.13 PM.png

 

Thanks
KV
▄︻̷̿┻̿═━一

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated. 

0 Karma
Get Updates on the Splunk Community!

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...

Splunk App Dev Community Updates – What’s New and What’s Next

Welcome to your go-to roundup of everything happening in the Splunk App Dev Community! Whether you're building ...

The Latest Cisco Integrations With Splunk Platform!

Join us for an exciting tech talk where we’ll explore the latest integrations in Cisco + Splunk! We’ve ...