<?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 rank data based on field within event? and output whole event while displaying in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314517#M94148</link>
    <description>&lt;P&gt;i got the above result too, but if you see the result is not taking into account "score".  Hence the rank is wrong as it just sorts by department&lt;/P&gt;

&lt;P&gt;( I understand the concept of streamstats, but my issue i'm not able to find an option to use, like max or perc )&lt;/P&gt;</description>
    <pubDate>Thu, 31 Aug 2017 20:46:17 GMT</pubDate>
    <dc:creator>koshyk</dc:creator>
    <dc:date>2017-08-31T20:46:17Z</dc:date>
    <item>
      <title>How to rank data based on field within event? and output whole event while displaying</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314513#M94144</link>
      <description>&lt;P&gt;I've got data say in following format&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;name,department,location,score
jack,finance,houston,220
jill,finance,london,490
jake,finance,paris,200
jude,finance,vegas,600
tom,developer,dubai,350
dave,developer,vegas,800
joe,developer,california,600
john,cto,moscow,700
judy,ceo,washington,750
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output needs ranking of the data grouped by department ; &amp;amp; ONLY the first two Ranks based on score should be displayed &lt;BR /&gt;
(Also please note, there could be one entry for certain department and in that case only Rank1 needs to be displayed)&lt;/P&gt;

&lt;P&gt;Required output is something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rank,name,department,location,score
rank1,jude,finance,vegas,600
rank2,jill,finance,london,490
rank1,lizy,support,vegas,900
rank2,bond,support,dubai,600
rank1,john,cto,moscow,700
rank1,judy,ceo,washington,750
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any simple SPL can you suggest?  &lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 14:24:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314513#M94144</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2017-08-31T14:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to rank data based on field within event? and output whole event while displaying</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314514#M94145</link>
      <description>&lt;P&gt;The &lt;CODE&gt;streamstats&lt;/CODE&gt; command can do that.  This example creates a running count for each department then discards all but the first two in each one.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | streamstats count as rank by department | where rank &amp;lt;=2 | table rank name department location score
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Aug 2017 15:26:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314514#M94145</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-08-31T15:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to rank data based on field within event? and output whole event while displaying</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314515#M94146</link>
      <description>&lt;P&gt;it didn't work  as expected as the "score" was not part of the streamstats equation. &lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 16:04:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314515#M94146</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2017-08-31T16:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to rank data based on field within event? and output whole event while displaying</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314516#M94147</link>
      <description>&lt;P&gt;One of the virtues of &lt;CODE&gt;streamstats&lt;/CODE&gt; is it does not filter out fields so all fields are available downstream even if they aren't part of the &lt;CODE&gt;streamstats&lt;/CODE&gt; command.&lt;BR /&gt;
What results did you get?  I get this with your sample data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rank    name    department  location    score
1   judy    ceo washington  750
1   john    cto moscow  700
1   joe developer   california  600
2   dave    developer   vegas   800
1   jude    finance vegas   600
2   jake    finance paris   200
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Aug 2017 17:02:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314516#M94147</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-08-31T17:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to rank data based on field within event? and output whole event while displaying</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314517#M94148</link>
      <description>&lt;P&gt;i got the above result too, but if you see the result is not taking into account "score".  Hence the rank is wrong as it just sorts by department&lt;/P&gt;

&lt;P&gt;( I understand the concept of streamstats, but my issue i'm not able to find an option to use, like max or perc )&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 20:46:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314517#M94148</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2017-08-31T20:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to rank data based on field within event? and output whole event while displaying</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314518#M94149</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults
| eval raw="jack,finance,houston,220::jill,finance,london,490::jake,finance,paris,200::jude,finance,vegas,600::tom,developer,dubai,350::dave,developer,vegas,800::joe,developer,california,600::john,cto,moscow,700::judy,ceo,washington,750"
| makemv delim="::" raw
| mvexpand raw
| rename raw AS _raw
| rex "^(?&amp;lt;name&amp;gt;[^,]+),(?&amp;lt;department&amp;gt;[^,]+),(?&amp;lt;location&amp;gt;[^,]+),(?&amp;lt;score&amp;gt;[^,]+)$"

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| sort 0 -score department
| streamstats current=t count AS JuNkT3Mp_rankNoTies BY department
| search JuNkT3Mp_rankNoTies&amp;lt;3
| eventstats min(JuNkT3Mp_rankNoTies) AS JuNkT3Mp_newFieldName BY score department
| fields - JuNkT3Mp_rankNoTies
| rename JuNkT3Mp_newFieldName AS rank
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Sep 2017 00:14:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314518#M94149</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-09-01T00:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to rank data based on field within event? and output whole event while displaying</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314519#M94150</link>
      <description>&lt;P&gt;All hail the hero. Thank you very much @woodcock.  Perfect answer and perfectly put with comments&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 11:12:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314519#M94150</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2017-09-01T11:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to rank data based on field within event? and output whole event while displaying</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314520#M94151</link>
      <description>&lt;P&gt;For those of you looking for a more general ranking, remove the &lt;CODE&gt;| search JuNkT3Mp_rankNoTies&amp;lt;3&lt;/CODE&gt; part.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 22:33:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-rank-data-based-on-field-within-event-and-output-whole/m-p/314520#M94151</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-09-01T22:33:56Z</dc:date>
    </item>
  </channel>
</rss>

