Splunk Search

Convert Multivalue field into Number

matthaeus
Explorer

Hey there,

I have extracted chart data from the raw field into multivalue fields. But I can't chart the data since splunk doesn't recoginse the the fields as numbers.

x_axis
y_axis
-1.292015
-1.282425
-1.27523
-1.26725
-1.258461
-1.248871
4.9024
5.129161
5.200173
5.327875
5.909696
6.406182

 

I have tried to convert it using:

|eval x_axis2=tonumber(trim(x_axis))

or:

| Convert num(x_axis)

but both didn't work. Could anybody help me out here?

Labels (3)
0 Karma

thambisetty
SplunkTrust
SplunkTrust

add below search to your search

 

| eval x_axis=split(x_axis,","),y_axis=split(y_axis,",")
| eval combine=mvzip(x_axis,y_axis)
| fields - x_axis,y_axis
| mvexpand combine
| eval x_axis=mvindex(split(combine,","),0),y_axis=mvindex(split(combine,","),1)
| fields - combine
| table x_axis y_axis

below will create sample events as well and show your results:

| makeresults | eval x_axis="-1.292015,-1.282425,-1.27523,-1.26725,-1.258461,-1.248871",y_axis="4.9024,5.129161,5.200173,5.327875,5.909696,6.406182"
| eval x_axis=split(x_axis,","),y_axis=split(y_axis,",")
| eval combine=mvzip(x_axis,y_axis)
| fields - x_axis,y_axis
| mvexpand combine
| eval x_axis=mvindex(split(combine,","),0),y_axis=mvindex(split(combine,","),1)
| fields - combine
| table x_axis y_axis

 

————————————
If this helps, give a like below.
0 Karma

matthaeus
Explorer

Thanks so much for your suggested solution, but for some reason I already don't have any results after the first line:

| eval x_axis=split(x_axis,","),y_axis=split(y_axis,",")
 
 

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Can you extract the x-axis and y-axis values into separate event rather than multi-value fields? if not, you could mvzip them together with a suitable delimiter, then mvexpand to get separate events. Then split the field and re-evaluate x-axis and y-axis. Then you will have something to chart.

0 Karma

matthaeus
Explorer

So I think I actually don't have a multivalue field, splunk just recognises it as one since it sees the "." as a delimiter rather than a comma.

0 Karma

matthaeus
Explorer

How exactly do you mean?

So I have extracted it using:

| rex field=_raw max_match=0 (?<x_axis>.\d.\d+);(?<y_axis>\d+.\d+)

 

Sorry, I'm quite new to splunk 😀

0 Karma

matthaeus
Explorer

Hmm.. it just gives me the error message: Error in 'eval' command: The 'mvmap' function is unsupported or undefined. 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Which version of splunk are you running?

0 Karma

matthaeus
Explorer

Splunk Enterprise

Version:7.2.10

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try this:

| eval x_axis=mvmap(x_axis, tonumber(x_axis))
| eval y_axis=mvmap(y_axis, tonumber(y_axis))
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...