<?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: Aggregating fields in JSON array in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249128#M74396</link>
    <description>&lt;P&gt;I did a little more digging and trouble shooting and found that during my import I was being presented with a warning on the entries that exceeded 10000 bytes.  I determined the config setting that controls that and increased the truncate value in props.conf.  Everything is working well now.  Thanks again.&lt;/P&gt;</description>
    <pubDate>Fri, 18 Mar 2016 21:24:21 GMT</pubDate>
    <dc:creator>mbosse</dc:creator>
    <dc:date>2016-03-18T21:24:21Z</dc:date>
    <item>
      <title>Aggregating fields in JSON array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249124#M74392</link>
      <description>&lt;P&gt;I'm relatively new to Splunk queries.  I have an event that contains JSON and within the JSON data is an array.  There's some data about a web page request, then an array of resources that make up the page, with some timing data for each resource.&lt;/P&gt;

&lt;P&gt;I'd like to get things like the resource with the longest duration for a given request, and the average duration across all resources for a given request.&lt;/P&gt;

&lt;P&gt;Here's the data:&lt;/P&gt;

&lt;P&gt;{&lt;BR /&gt;
 "ts":"2016-01-21T12:15:16.0451054-05:00",&lt;BR /&gt;
 "id":"a95dc052-de57-45a5-be8b-4eee1b7a39ec",&lt;BR /&gt;
 "url":"&lt;A href="http://www.mysite.com/default.htm" target="_blank"&gt;http://www.mysite.com/default.htm&lt;/A&gt;",&lt;BR /&gt;
 "res":&lt;BR /&gt;
    [&lt;BR /&gt;
    {&lt;BR /&gt;
       "r_tid":"a95dc052-de57-45a5-be8b-4eee1b7a39ec",&lt;BR /&gt;
       "r_nm":"&lt;A href="http://www.mysite.com/file1.css" target="_blank"&gt;http://www.mysite.com/file1.css&lt;/A&gt;",&lt;BR /&gt;
       "duration":8.2&lt;BR /&gt;
    },&lt;BR /&gt;
    {&lt;BR /&gt;
       "r_tid":"a95dc052-de57-45a5-be8b-4eee1b7a39ec",&lt;BR /&gt;
       "r_nm":"&lt;A href="http://www.mysite.com/file2.css" target="_blank"&gt;http://www.mysite.com/file2.css&lt;/A&gt;",&lt;BR /&gt;
       "duration":7.731&lt;BR /&gt;
    },&lt;BR /&gt;
    {&lt;BR /&gt;
       "r_tid":"a95dc052-de57-45a5-be8b-4eee1b7a39ec",&lt;BR /&gt;
       "r_nm":"&lt;A href="http://www.mysite.com/file1.js" target="_blank"&gt;http://www.mysite.com/file1.js&lt;/A&gt;",&lt;BR /&gt;
       "duration":16.909&lt;BR /&gt;
    }&lt;BR /&gt;
   ]&lt;BR /&gt;
}&lt;/P&gt;

&lt;P&gt;And for max duration, something like this as the output:&lt;BR /&gt;
r_nm, duration&lt;BR /&gt;
&lt;A href="http://www.mysite.com/file1.js" target="_blank"&gt;http://www.mysite.com/file1.js&lt;/A&gt;, 16.909&lt;/P&gt;

&lt;P&gt;and for the average, something like this:&lt;BR /&gt;
url, average_duration&lt;BR /&gt;
&lt;A href="http://www.mysite.com/default.htm" target="_blank"&gt;http://www.mysite.com/default.htm&lt;/A&gt;, 10.947&lt;/P&gt;

&lt;P&gt;I've tried spath a number of different ways based on other posts in here, but can't seem to get the right syntax.  Any help would be greatly appreciated.  The t_id for each resource will always equal the id of the request, in case a join is needed to do this.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:06:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249124#M74392</guid>
      <dc:creator>mbosse</dc:creator>
      <dc:date>2020-09-29T09:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating fields in JSON array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249125#M74393</link>
      <description>&lt;P&gt;Here's an idea:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval _raw = "{\"ts\": \"2016-01-21T12:15:16.0451054-05:00\",\"id\": \"a95dc052-de57-45a5-be8b-4eee1b7a39ec\",\"url\": \"http://www.mysite.com/default.htm\",\"res\": [{\"r_tid\": \"a95dc052-de57-45a5-be8b-4eee1b7a39ec\",\"r_nm\": \"http://www.mysite.com/file1.css\",\"duration\": 8.2}, {\"r_tid\": \"a95dc052-de57-45a5-be8b-4eee1b7a39ec\",\"r_nm\": \"http://www.mysite.com/file2.css\",\"duration\": 7.731}, {\"r_tid\": \"a95dc052-de57-45a5-be8b-4eee1b7a39ec\",\"r_nm\": \"http://www.mysite.com/file1.js\",\"duration\": 16.909}]}" 
| spath url | spath res{} output=res | mvexpand res | spath input=res
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The first line generates a dummy event using your example, the second line extracts the &lt;CODE&gt;url&lt;/CODE&gt;, splits the event per resource, and extracts the resource fields. (Side note: If you already have configured field extractions and see a &lt;CODE&gt;url&lt;/CODE&gt; field you can drop the first &lt;CODE&gt;spath&lt;/CODE&gt;.) After that, you can append one of these two to get your statistics:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats avg(duration) by url
| stats max(duration) by r_nm
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Mar 2016 22:04:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249125#M74393</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-03-15T22:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating fields in JSON array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249126#M74394</link>
      <description>&lt;P&gt;Thanks martin_mueller.  When I used this on some real data, I had to add "| fields url, r_dur, r_nm" before the stats in order to actually get a value.  I still don't fully understand when to include the fields clause, but that got what I needed.  However, in the real data, on the one request event I'm validating with, there are 91 resources in the JSON array.  For some reason, only the first 34 in the array are being used to calculate the average or the max.  I'll likely post another question in here specific to that.  Otherwise, I believe what you provided is working with the additional of the fields clause.  Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:08:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249126#M74394</guid>
      <dc:creator>mbosse</dc:creator>
      <dc:date>2020-09-29T09:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating fields in JSON array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249127#M74395</link>
      <description>&lt;P&gt;Oh - forgot to mention, if I use the dummy data approach and put exactly the same data with the 91 resources in the JSON array as was imported, it seems to work fine.  So this tells me it's likely a limitation on the import, the indexing, or on the search (or maybe a combination).  So again, thanks for your idea.  I think what you proposed is a sound approach and now I have a different issue to work through.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 19:38:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249127#M74395</guid>
      <dc:creator>mbosse</dc:creator>
      <dc:date>2016-03-18T19:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating fields in JSON array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249128#M74396</link>
      <description>&lt;P&gt;I did a little more digging and trouble shooting and found that during my import I was being presented with a warning on the entries that exceeded 10000 bytes.  I determined the config setting that controls that and increased the truncate value in props.conf.  Everything is working well now.  Thanks again.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 21:24:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249128#M74396</guid>
      <dc:creator>mbosse</dc:creator>
      <dc:date>2016-03-18T21:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating fields in JSON array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249129#M74397</link>
      <description>&lt;P&gt;Well done &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2016 21:46:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249129#M74397</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-03-18T21:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating fields in JSON array</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249130#M74398</link>
      <description>&lt;P&gt;i still cant get real data to display anything other than a big count. didnt make a difference adding fields. what is feilds menat ot be doing in this scenario? why would eval behave different to real data?&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2016 05:25:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Aggregating-fields-in-JSON-array/m-p/249130#M74398</guid>
      <dc:creator>paulwrussell</dc:creator>
      <dc:date>2016-05-23T05:25:07Z</dc:date>
    </item>
  </channel>
</rss>

