<?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 Grouping by String and Sorting by Average in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Grouping-by-String-and-Sorting-by-Average/m-p/234807#M69741</link>
    <description>&lt;P&gt;Hi there!&lt;/P&gt;

&lt;P&gt;I have run the following search...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="prop_data" uri=*/property/*/* | stats avg(execution_time) by uri | head 10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which produces results like...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/testfolder1/property/for-sale-adverts.json 1.142857
/testfolder1/property/10006959/adverts.json 103.000000
/testfolder1/property/10006959/forrent.json 3.000000
/testfolder1/property/10007021/adverts.json 14.000000
/testfolder1/property/10007021/forrent.json 4.000000
/testfolder1/property/10010951/adverts.json 13.000000
/testfolder1/property/10010951/single-ad/15892269.json  18.500000
/testfolder1/property/10010951/single-ad/80817600.json  15.500000
/testfolder1/property/10015532/adverts.json 197.000000
/testfolder1/property/10015532/single-ad/19372287.json  15.000000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ideally, what I'm actually wanting (broken into dot points for easier reading) is:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;the top 10 grouped uri's sorted in decending order by the average execution_time for that "grouped set"... &lt;/LI&gt;
&lt;LI&gt;where those uri's are grouped by:  [whatever is between the 3rd and 4th slash that doesn't contain numbers] and [whatever is between the 4th and 5th slash]&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;So in the output above, there would only be an average execution time for:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;for-sale-adverts.json  &lt;EM&gt;(this is the only "uri" that would be captured by my first grouping)&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;adverts.json&lt;/LI&gt;
&lt;LI&gt;forrent.json&lt;/LI&gt;
&lt;LI&gt;single-ad&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Any help on this one is MUCH appreciated!!!&lt;/P&gt;

&lt;P&gt;Cheers,&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
    <pubDate>Thu, 24 Sep 2015 00:13:26 GMT</pubDate>
    <dc:creator>stanbridge</dc:creator>
    <dc:date>2015-09-24T00:13:26Z</dc:date>
    <item>
      <title>Grouping by String and Sorting by Average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-by-String-and-Sorting-by-Average/m-p/234807#M69741</link>
      <description>&lt;P&gt;Hi there!&lt;/P&gt;

&lt;P&gt;I have run the following search...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="prop_data" uri=*/property/*/* | stats avg(execution_time) by uri | head 10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which produces results like...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/testfolder1/property/for-sale-adverts.json 1.142857
/testfolder1/property/10006959/adverts.json 103.000000
/testfolder1/property/10006959/forrent.json 3.000000
/testfolder1/property/10007021/adverts.json 14.000000
/testfolder1/property/10007021/forrent.json 4.000000
/testfolder1/property/10010951/adverts.json 13.000000
/testfolder1/property/10010951/single-ad/15892269.json  18.500000
/testfolder1/property/10010951/single-ad/80817600.json  15.500000
/testfolder1/property/10015532/adverts.json 197.000000
/testfolder1/property/10015532/single-ad/19372287.json  15.000000
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ideally, what I'm actually wanting (broken into dot points for easier reading) is:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;the top 10 grouped uri's sorted in decending order by the average execution_time for that "grouped set"... &lt;/LI&gt;
&lt;LI&gt;where those uri's are grouped by:  [whatever is between the 3rd and 4th slash that doesn't contain numbers] and [whatever is between the 4th and 5th slash]&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;So in the output above, there would only be an average execution time for:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;for-sale-adverts.json  &lt;EM&gt;(this is the only "uri" that would be captured by my first grouping)&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;adverts.json&lt;/LI&gt;
&lt;LI&gt;forrent.json&lt;/LI&gt;
&lt;LI&gt;single-ad&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Any help on this one is MUCH appreciated!!!&lt;/P&gt;

&lt;P&gt;Cheers,&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2015 00:13:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-by-String-and-Sorting-by-Average/m-p/234807#M69741</guid>
      <dc:creator>stanbridge</dc:creator>
      <dc:date>2015-09-24T00:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping by String and Sorting by Average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-by-String-and-Sorting-by-Average/m-p/234808#M69742</link>
      <description>&lt;P&gt;Something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="prop_data" uri=*/property/*/*
 | rex field=uri mode=sed "s=(/[^\/]+){2}.+?([^\d/]+).*=\2="
 | stats avg(execution_time) by uri 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Sep 2015 00:56:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-by-String-and-Sorting-by-Average/m-p/234808#M69742</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2015-09-24T00:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping by String and Sorting by Average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-by-String-and-Sorting-by-Average/m-p/234809#M69743</link>
      <description>&lt;P&gt;Thanks yuanliu, but no results unfortunately.&lt;/P&gt;

&lt;P&gt;If it helps, here's some standard regex that successfully finds all of the strings I would want to group by...&lt;/P&gt;

&lt;P&gt;(?&amp;lt;=\/)(?!.*\/\D)\D[^\/]+&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2015 01:45:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-by-String-and-Sorting-by-Average/m-p/234809#M69743</guid>
      <dc:creator>stanbridge</dc:creator>
      <dc:date>2015-09-24T01:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping by String and Sorting by Average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-by-String-and-Sorting-by-Average/m-p/234810#M69744</link>
      <description>&lt;P&gt;If you have the regex, that should be all you need.  All I'm suggesting is to extract that string and group accordingly.  I don't get how D is used in the above, but I can think of another workaround: Just get rid of all numerals.  Like this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="prop_data" uri=*/property/*/*
 | eval uri=replace(uri,".+/property/","")
 | eval uri=replace(uri,"/\d+(\.json$|/)","")
 | stats avg(execution_time) by uri 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Sep 2015 06:35:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-by-String-and-Sorting-by-Average/m-p/234810#M69744</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2015-09-24T06:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping by String and Sorting by Average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-by-String-and-Sorting-by-Average/m-p/234811#M69745</link>
      <description>&lt;P&gt;Hi Yuanliu!&lt;/P&gt;

&lt;P&gt;Sorry for the delayed reply, I'm currently only alloowed 2 replies a day.  I had this comment ready to go yesterday.&lt;/P&gt;

&lt;P&gt;"Actually, I have it!&lt;/P&gt;

&lt;P&gt;I just used two separate rex's.  One to remove junk from the start of the wanted part of the string and a second one to remove stuff after the wanted part of the string.&lt;/P&gt;

&lt;P&gt;Thanks anyway for your help Yuanliu!"&lt;/P&gt;

&lt;P&gt;The regex I had above was good for finding the values in the middle of the string but didn't work ideally for Splunk.&lt;/P&gt;

&lt;P&gt;Thanks for your suggestions though, very much appreciated!&lt;/P&gt;

&lt;P&gt;Cheers,&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2015 23:07:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-by-String-and-Sorting-by-Average/m-p/234811#M69745</guid>
      <dc:creator>stanbridge</dc:creator>
      <dc:date>2015-09-24T23:07:00Z</dc:date>
    </item>
  </channel>
</rss>

