Getting Data In

Splunk to split a multivalue json

sssignals
Path Finder

Hi Splunk community

I have been trying for 2 days using spath, mvindex, split on the following json... this is a row in Splunk with 4 event sizes and times. Some event have 1 event size and time. Some have more. I want to access the individual event size and time eg.
| table flowKey eventsize1 eventtime1 eventsize2 eventtime2

Please give me some advice and guidance. Thanks so much.

{"_id":{"$oid":"dfsahu13fd"},"flowKey":"null,null,...", "size_of_events":[1.1121356e+08,1.1121357e+08,1.1121357e+08,1.1121358e+08],"time_of_events":[{"$numberLong":"1548454548"},{"$numberLong":"1548454549"},{"$numberLong":"1548454555"},{"$numberLong":"1548454559"}]...}

0 Karma
1 Solution

FrankVl
Ultra Champion

Dealing with a variable number of fields is going to be difficult, I don't know of any proper way to do that.

Is there a large variance in the number of sizes and times that can be in an event? If it is limited to max. 5 or so, you could do something like:

...do rex/spath extractions that result in mulitvalued fields `eventsizes` and `eventtimes`...
| eval eventsize1 = mvindex(eventsizes,0)
| eval eventsize2 = mvindex(eventsizes,1)
| eval eventsize3 = mvindex(eventsizes,2)
| eval eventsize4 = mvindex(eventsizes,3)
| eval eventsize5 = mvindex(eventsizes,4)
| eval eventtime1 = mvindex(eventtimes,0)
| eval eventtime2 = mvindex(eventtimes,1)
| eval eventtime3 = mvindex(eventtimes,2)
| eval eventtime4 = mvindex(eventtimes,3)
| eval eventtime5 = mvindex(eventtimes,4)
| table flowKey eventsize1 eventtime1 eventsize2 eventtime2 eventsize3 eventtime3 eventsize4 eventtime4 eventsize5 eventtime5 

But as you can see, that gets very ugly if the range of possible number of 'columns' can be much bigger.

View solution in original post

FrankVl
Ultra Champion

Dealing with a variable number of fields is going to be difficult, I don't know of any proper way to do that.

Is there a large variance in the number of sizes and times that can be in an event? If it is limited to max. 5 or so, you could do something like:

...do rex/spath extractions that result in mulitvalued fields `eventsizes` and `eventtimes`...
| eval eventsize1 = mvindex(eventsizes,0)
| eval eventsize2 = mvindex(eventsizes,1)
| eval eventsize3 = mvindex(eventsizes,2)
| eval eventsize4 = mvindex(eventsizes,3)
| eval eventsize5 = mvindex(eventsizes,4)
| eval eventtime1 = mvindex(eventtimes,0)
| eval eventtime2 = mvindex(eventtimes,1)
| eval eventtime3 = mvindex(eventtimes,2)
| eval eventtime4 = mvindex(eventtimes,3)
| eval eventtime5 = mvindex(eventtimes,4)
| table flowKey eventsize1 eventtime1 eventsize2 eventtime2 eventsize3 eventtime3 eventsize4 eventtime4 eventsize5 eventtime5 

But as you can see, that gets very ugly if the range of possible number of 'columns' can be much bigger.

sssignals
Path Finder

Hi FrankVI

I swore I tried something like your solution but I cannot hack it.
Maybe I am starting to see stars and commas.

Thanks for your speedy help! Really works!

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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

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