<?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: Find top n in each group in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70410#M17618</link>
    <description>&lt;P&gt;Any response, please?&lt;/P&gt;</description>
    <pubDate>Sat, 22 Jun 2013 16:01:57 GMT</pubDate>
    <dc:creator>saumitra</dc:creator>
    <dc:date>2013-06-22T16:01:57Z</dc:date>
    <item>
      <title>Find top n in each group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70409#M17617</link>
      <description>&lt;P&gt;I have a collection of records in [object_name, execution_time] format. I want to gather top 10 (i.e. first 10 in sorted sequence) execution time values for each object.&lt;/P&gt;

&lt;P&gt;I could extract execution times grouped by object name by &lt;/P&gt;

&lt;P&gt;&lt;EM&gt;index=myindex | stats values(execTime) as MaxTime by objectName&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;But I could not find way to sort the individual groups and getting top 10 in each of them.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;[EDIT]&lt;/P&gt;

&lt;P&gt;Looks like I did not explain the question well. Actually I have a database for how much time did the web service  take to execute, in different calls. (I called web service as 'object_name' above). There are various web services.&lt;BR /&gt;
 e.g. I have web services w1,w2, .., wn. I have following records&lt;BR /&gt;
[w1,e11] [w1,e12] [w1, e13] ... [w2,e21] [w2,e22] [w2,e23] .... [wn,en1] [wn,en2] [wn,en3] ....&lt;BR /&gt;
e11 represents the time w1 took in its first call. &lt;/P&gt;

&lt;P&gt;Now I want the following&lt;BR /&gt;
&lt;STRONG&gt;w1:&lt;/STRONG&gt; t11,t12, ...,t1n&lt;BR /&gt;
&lt;STRONG&gt;w2:&lt;/STRONG&gt; t21,t22, ...,t2n&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;t11, t12, t1n are top n for w1. Top n are the highest 'n' values of e11,e12,,e13 ... in sorted sequence.&lt;BR /&gt;
e.g. If e11,e12,e13,... are ,8,8,8,8,10,7,7,7,9,9 then Top two are 10,9. &lt;/P&gt;

&lt;P&gt;Now Splunk top function would not work here because I would give me 8,7 which are the most frequent two. I don't want that. &lt;/P&gt;

&lt;P&gt;It's like list of students' scores in each subject. I want n highest scoring students for each subject. Hope that now it's clear.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2013 14:52:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70409#M17617</guid>
      <dc:creator>saumitra</dc:creator>
      <dc:date>2013-06-20T14:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find top n in each group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70410#M17618</link>
      <description>&lt;P&gt;Any response, please?&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2013 16:01:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70410#M17618</guid>
      <dc:creator>saumitra</dc:creator>
      <dc:date>2013-06-22T16:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Find top n in each group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70411#M17619</link>
      <description>&lt;P&gt;Not entirely sure what exact output you're after. &lt;CODE&gt;top 10 execTime by objectName&lt;/CODE&gt;?&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2013 16:31:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70411#M17619</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-06-22T16:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: Find top n in each group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70412#M17620</link>
      <description>&lt;P&gt;Like Ayn I don't quite understand what you're after. Maybe you could post some sample events with the desired output format.&lt;/P&gt;

&lt;P&gt;Maybe one of those works for you:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex | table execTime,objectName | sort -execTime |  streamstats count by objectName |  stats  list(eval(if(count&amp;lt;11,execTime,null()))) as MaxTime  by objectName


index=myindex | table execTime,objectName | sort -execTime |  streamstats count by objectName |  where count &amp;lt; 11
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Jun 2013 21:19:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70412#M17620</guid>
      <dc:creator>chris</dc:creator>
      <dc:date>2013-06-22T21:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Find top n in each group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70413#M17621</link>
      <description>&lt;P&gt;I have edited qn now. Top would not work for me.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jun 2013 15:34:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70413#M17621</guid>
      <dc:creator>saumitra</dc:creator>
      <dc:date>2013-06-23T15:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: Find top n in each group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70414#M17622</link>
      <description>&lt;P&gt;Tried these, but both gave more than 10 results for every objectName.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jun 2013 16:06:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70414#M17622</guid>
      <dc:creator>saumitra</dc:creator>
      <dc:date>2013-06-23T16:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: Find top n in each group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70415#M17623</link>
      <description>&lt;P&gt;Hm my bad, sorry. I updated the answer. The streamstats part was not correct. This is a search that works  on internal splunk data: index=_internal source="&lt;EM&gt;metrics.log" largest_size="&lt;/EM&gt;" | table name,largest_size | sort -largest_size | streamstats count by name | stats list(eval(if(count&amp;lt;11,largest_size,null()))) as Values  by name&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:09:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70415#M17623</guid>
      <dc:creator>chris</dc:creator>
      <dc:date>2020-09-28T14:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: Find top n in each group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70416#M17624</link>
      <description>&lt;P&gt;Sorry for delay, After bit tweaking in your last query, following worked for me:&lt;BR /&gt;
index=myIndex | eval time=execution_time/1000000.0 | table object_name,time | sort -time | streamstats count by object_name | stats list(eval(if(count&amp;lt;11,execution_time,null()))) as Values  by object_name&lt;BR /&gt;
Thanks !!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:11:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-top-n-in-each-group/m-p/70416#M17624</guid>
      <dc:creator>saumitra</dc:creator>
      <dc:date>2020-09-28T14:11:27Z</dc:date>
    </item>
  </channel>
</rss>

