<?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: How to accumulate a numerical field of a multivalue object based on other field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-accumulate-a-numerical-field-of-a-multivalue-object-based/m-p/636971#M221184</link>
    <description>&lt;LI-CODE lang="markup"&gt;| spath input=event
| rename colors{}.* as *
| eval count=mvcount(color)
| eval row=mvrange(0,count)
| mvexpand row
| eval color=mvindex(color,row)
| eval appearances=mvindex(appearances,row)
| stats sum(appearances) as appearances by color&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 31 Mar 2023 19:45:38 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2023-03-31T19:45:38Z</dc:date>
    <item>
      <title>How to accumulate a numerical field of a multivalue object based on other field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-accumulate-a-numerical-field-of-a-multivalue-object-based/m-p/636912#M221181</link>
      <description>&lt;P&gt;I have many event with the following format:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EVENT 1&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 'colors': [&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'color': 'red', 'appearances': 3},&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'color': 'blue', 'appearances': 2},&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'color': 'yellow', 'appearances': 4}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EVENT 2&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 'colors': [&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'color': 'green', 'appearances': 1},&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'color': 'blue', 'appearances': 4},&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'color': 'yellow', 'appearances': 2}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to accumulate the field appearances after verifying each event grouped by the field color to have the following output:&lt;/P&gt;
&lt;P&gt;| ---------------------------------------------------------------------------------- |&lt;/P&gt;
&lt;P&gt;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Color&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Appearances&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&lt;/P&gt;
&lt;P&gt;| ---------------------------------------------------------------------------------- |&lt;/P&gt;
&lt;P&gt;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; blue&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&lt;/P&gt;
&lt;P&gt;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; red&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&lt;/P&gt;
&lt;P&gt;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; yellow&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&lt;/P&gt;
&lt;P&gt;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; green&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&lt;/P&gt;
&lt;P&gt;|&amp;nbsp; ---------------------------------------------------------------------------------- |&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone know how to obtain this result, I have been playing with mv functions, but I am not able to produce the expected output.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 16:39:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-accumulate-a-numerical-field-of-a-multivalue-object-based/m-p/636912#M221181</guid>
      <dc:creator>gorkazabarte</dc:creator>
      <dc:date>2023-03-31T16:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to accumulate a numerical field of a multivalue object based on other field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-accumulate-a-numerical-field-of-a-multivalue-object-based/m-p/636971#M221184</link>
      <description>&lt;LI-CODE lang="markup"&gt;| spath input=event
| rename colors{}.* as *
| eval count=mvcount(color)
| eval row=mvrange(0,count)
| mvexpand row
| eval color=mvindex(color,row)
| eval appearances=mvindex(appearances,row)
| stats sum(appearances) as appearances by color&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 31 Mar 2023 19:45:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-accumulate-a-numerical-field-of-a-multivalue-object-based/m-p/636971#M221184</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-03-31T19:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to accumulate a numerical field of a multivalue object based on other field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-accumulate-a-numerical-field-of-a-multivalue-object-based/m-p/638211#M221220</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;'s answer assumes that the JSON is contained in a field named event. &amp;nbsp;If the events are raw, you would already have flattened fields named colors{}.*. &amp;nbsp;Performing calculation on array elements using flattened field can obscure the underlying mathematics. &amp;nbsp;So, here I give an alternative, more semantic approach. (I'll take the assumption that the events are raw; if not, just add one more spath at top as ITWhisperer demonstrates.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path=colors{}
| mvexpand colors{}
| spath input=colors{}
| stats sum(appearances) as appearances by color&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your sample data give&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;color&lt;/TD&gt;&lt;TD&gt;appearances&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;blue&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;green&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;red&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;yellow&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is data emulation that you can play with and compare with real data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval data = split("{
    \"colors\": [ 
        {\"color\": \"red\", \"appearances\": 3},
        {\"color\": \"blue\", \"appearances\": 2},
        {\"color\": \"yellow\", \"appearances\": 4}
        ]
}|{
    \"colors\": [ 
        {\"color\": \"green\", \"appearances\": 1},
        {\"color\": \"blue\", \"appearances\": 4},
        {\"color\": \"yellow\", \"appearances\": 2}
        ]
}", "|")
| mvexpand data
| rename data AS _raw
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One more note: When you share anonymized data, please make sure to preserve the original data format. &amp;nbsp;The ones in your OP used incorrect quotation marks. &amp;nbsp;They also missed closing brackets for arrays. &amp;nbsp;This makes the volunteers' work more difficult.&lt;/P&gt;&lt;P&gt;If your data are truly conformant, they should look like these:&lt;/P&gt;&lt;PRE&gt;{
    "colors": [ 
        {"color": "red", "appearances": 3},
        {"color": "blue", "appearances": 2},
        {"color": "yellow", "appearances": 4}
        ]
}
{
    "colors": [ 
        {"color": "green", "appearances": 1},
        {"color": "blue", "appearances": 4},
        {"color": "yellow", "appearances": 2}
        ]
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Apr 2023 05:56:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-accumulate-a-numerical-field-of-a-multivalue-object-based/m-p/638211#M221220</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-04-02T05:56:58Z</dc:date>
    </item>
  </channel>
</rss>

