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

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...