Splunk Search

How to compare the values from same fields?

saurabh_ha
Engager

saurabh_ha_0-1664820432808.png

I want to create the new_field when other values of field_1 is less than of first value.
Here in below example as 23 greater than other values then do sum of all which is 44.
for 10 is the smallest then its result is 10
for 11 there is one more value is less which is 10 then do sum with 10 then result is 21

Labels (1)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

The following will work in Splunk 9 with the new multivalue mode in foreach.

| stats values(field_1) as field_1
| foreach field_1 mode=multivalue
    [eval new_field = mvappend(new_field, tostring(if(isnull(new_field), 0, max(new_field)) + <<ITEM>>))]
| eval zip = mvzip(field_1, new_field, ":")
| mvexpand zip
| eval zip = split(zip, ":")
| eval field_1 = mvindex(zip, 0), new_field = mvindex(zip, 1)

(If you need to access other fields in original search, modify "group by" clause or use eventstats as opposed to stats.)

I totally thought this could be solved with mvmap (no need for Splunk 9), but I couldn't get that to work.

View solution in original post

0 Karma

yuanliu
SplunkTrust
SplunkTrust

The following will work in Splunk 9 with the new multivalue mode in foreach.

| stats values(field_1) as field_1
| foreach field_1 mode=multivalue
    [eval new_field = mvappend(new_field, tostring(if(isnull(new_field), 0, max(new_field)) + <<ITEM>>))]
| eval zip = mvzip(field_1, new_field, ":")
| mvexpand zip
| eval zip = split(zip, ":")
| eval field_1 = mvindex(zip, 0), new_field = mvindex(zip, 1)

(If you need to access other fields in original search, modify "group by" clause or use eventstats as opposed to stats.)

I totally thought this could be solved with mvmap (no need for Splunk 9), but I couldn't get that to work.

0 Karma

saurabh_ha
Engager

Thanks for the response.

It is working as expected  in our UAT as you mentioned

0 Karma
Get Updates on the Splunk Community!

Dashboard Studio Challenge - Learn New Tricks, Showcase Your Skills, and Win Prizes!

Reimagine what you can do with your dashboards. Dashboard Studio is Splunk’s newest dashboard builder to ...

Introducing Edge Processor: Next Gen Data Transformation

We get it - not only can it take a lot of time, money and resources to get data into Splunk, but it also takes ...

Take the 2021 Splunk Career Survey for $50 in Amazon Cash

Help us learn about how Splunk has impacted your career by taking the 2021 Splunk Career Survey. Last year’s ...