<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Accumulate values for a multi value field by key in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Accumulate-values-for-a-multi-value-field-by-key/m-p/516376#M145097</link>
    <description>&lt;P&gt;`mvexpand stages` blows up memory unfortunately.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Aug 2020 20:07:25 GMT</pubDate>
    <dc:creator>unbelievable_ma</dc:creator>
    <dc:date>2020-08-26T20:07:25Z</dc:date>
    <item>
      <title>Accumulate values for a multi value field by key</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Accumulate-values-for-a-multi-value-field-by-key/m-p/516332#M145088</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Let's say I can get this table using some Splunk query.&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;id&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;stages&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="114px"&gt;1&lt;/TD&gt;&lt;TD width="50%" height="114px"&gt;&lt;P&gt;key1,100&lt;/P&gt;&lt;P&gt;key2,200&lt;/P&gt;&lt;P&gt;key3,300&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;2&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;&lt;P&gt;key1,50&lt;/P&gt;&lt;P&gt;key2,150&lt;/P&gt;&lt;P&gt;key3,250&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%" height="25px"&gt;3&lt;/TD&gt;&lt;TD width="50%" height="25px"&gt;&amp;nbsp;&lt;P&gt;key1,150&lt;/P&gt;&lt;P&gt;key2,250&lt;/P&gt;&lt;P&gt;key3,350&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Given this data I want the result, that is I want to reduce (average) over the keys.&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;key&lt;/TD&gt;&lt;TD width="50%"&gt;avg&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;key1&lt;/TD&gt;&lt;TD width="50%"&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;key2&lt;/TD&gt;&lt;TD width="50%"&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;key3&lt;/TD&gt;&lt;TD width="50%"&gt;300&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to use mvexpand for this but Splunk runs out of memory and the results get truncated. So I want something more like a reduce function that can accumulate this mv field by key. Is this possible to do through a splunk query?&lt;BR /&gt;&lt;BR /&gt;Here is what I have tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;`data_source`
    | fields id, stages{}.name as stage_name, somejson{}.duration as stage_duration
    | eval stages=mvzip(stage_name, stage_duration)
    | eval stages=mvfilter(match(stages, "key*"))
    | mvexpand stages
    | eval stages=split(stages, ",")
    | eval stage_name=mvindex(stages,0)
    | eval stage_duration=mvindex(stages,1)
    | stats avg(stage_duration) by stage_name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to do something more efficient than `mvexpand stages` that helps me do the reduction without blowing up memory.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Aug 2020 17:34:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Accumulate-values-for-a-multi-value-field-by-key/m-p/516332#M145088</guid>
      <dc:creator>unbelievable_ma</dc:creator>
      <dc:date>2020-08-26T17:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Accumulate values for a multi value field by key</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Accumulate-values-for-a-multi-value-field-by-key/m-p/516360#M145091</link>
      <description>&lt;P&gt;| eventstats count&lt;/P&gt;&lt;P&gt;| mvexpand stages&lt;/P&gt;&lt;P&gt;| rex field=stages “(?&amp;lt;key&amp;gt;[^,]+),(?&amp;lt;value&amp;gt;\d+)”&lt;/P&gt;&lt;P&gt;| stats values(count) as count sum(value) as value by key&lt;/P&gt;&lt;P&gt;| eval avg=value/count&lt;/P&gt;&lt;P&gt;| table key avg&lt;/P&gt;&lt;P&gt;Note: replace double quotes in rex command with double quotes from your keyboard.&lt;/P&gt;&lt;P&gt;not tested also.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Aug 2020 19:15:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Accumulate-values-for-a-multi-value-field-by-key/m-p/516360#M145091</guid>
      <dc:creator>thambisetty</dc:creator>
      <dc:date>2020-08-26T19:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Accumulate values for a multi value field by key</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Accumulate-values-for-a-multi-value-field-by-key/m-p/516376#M145097</link>
      <description>&lt;P&gt;`mvexpand stages` blows up memory unfortunately.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Aug 2020 20:07:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Accumulate-values-for-a-multi-value-field-by-key/m-p/516376#M145097</guid>
      <dc:creator>unbelievable_ma</dc:creator>
      <dc:date>2020-08-26T20:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Accumulate values for a multi value field by key</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Accumulate-values-for-a-multi-value-field-by-key/m-p/516577#M145195</link>
      <description>&lt;P&gt;Yes. If you are applying on raw events. Try to apply after transforming commands like top,chart, stats, timechart. This will reduce number of events.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 19:05:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Accumulate-values-for-a-multi-value-field-by-key/m-p/516577#M145195</guid>
      <dc:creator>thambisetty</dc:creator>
      <dc:date>2020-08-27T19:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: Accumulate values for a multi value field by key</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Accumulate-values-for-a-multi-value-field-by-key/m-p/516601#M145201</link>
      <description>&lt;P&gt;Unfortunately I can't do that. I don't have a lot of different keys. Around 10-12.&lt;BR /&gt;I ended up solving this by splitting the key manually into separate columns and then aggregating without using mvexpand. Something like:&lt;BR /&gt;&lt;BR /&gt;| fields name, value&lt;BR /&gt;| eval stages=mvzip(name, value)&lt;BR /&gt;-- the sort helps here to make sure the keys appear always in the same order&lt;BR /&gt;| eval stages=mvsort(mvfilter(match(stages, "key-*"))&lt;BR /&gt;| eval key0=mvindex(stages,0)&lt;BR /&gt;| rex field=key0 "(?&amp;lt;name&amp;gt;.+),(?&amp;lt;key0&amp;gt;.+)"&lt;BR /&gt;| eval key1=mvindex(stages,0)&lt;BR /&gt;| rex field=key1 "(?&amp;lt;name&amp;gt;.+),(?&amp;lt;key1&amp;gt;.+)"&lt;BR /&gt;-- similarly for all different keys&lt;BR /&gt;| timechart span=1h&lt;BR /&gt;&amp;nbsp; &amp;nbsp; median(key1) as key1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; median(key2) as key2&lt;BR /&gt;&amp;nbsp; &amp;nbsp; -- other keys here&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;This expands to exactly the same amount of data as before but no memory issues.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 20:41:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Accumulate-values-for-a-multi-value-field-by-key/m-p/516601#M145201</guid>
      <dc:creator>unbelievable_ma</dc:creator>
      <dc:date>2020-08-27T20:41:35Z</dc:date>
    </item>
  </channel>
</rss>

