<?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: Top 10 values for each field value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Top-10-values-for-each-field-value/m-p/360252#M106511</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/217544"&gt;@matansocher&lt;/a&gt;, following is a run anywhere example which generates a mock series of 8 value per regression_target. sort and retains unique regression_test values using &lt;CODE&gt;values()&lt;/CODE&gt; statistical function. It then counts the values per series using &lt;CODE&gt;streamstats&lt;/CODE&gt; after reversing the series (or sort descending). Finally filters top 3 values for each series using &lt;CODE&gt;where&lt;/CODE&gt; condition.&lt;/P&gt;

&lt;P&gt;PS: Commands until &lt;CODE&gt;| table&lt;/CODE&gt; generate mock data as per question. You can hook in your base search instead. Also change where &lt;CODE&gt;counter&amp;lt;=3&lt;/CODE&gt; with &lt;CODE&gt;10&lt;/CODE&gt; as per your use case.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval data="bbb|770;ccc|870;bbb|970;ccc|780;aaa|780;bbb|670;ccc|950;aaa|320;bbb|230;ccc|345;aaa|500;bbb|200;ccc|600;aaa|200;bbb|150;ccc|300;aaa|800;bbb|600;aaa|400;ccc|900;bbb|200;aaa|300;ccc|400;aaa|900;bbb|800;ccc|600"
|  makemv data delim=";"
|  mvexpand data
|  eval data=split(data,"|")
|  eval regression_target=mvindex(data,0)
|  eval regression_tests=mvindex(data,1)
|  table regression_target regression_tests
|  stats values(regression_tests) as regression_tests by regression_target
|  mvexpand regression_tests
|  reverse
|  streamstats count as counter by regression_target
|  where counter&amp;lt;=3
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Sep 2020 16:46:05 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2020-09-29T16:46:05Z</dc:date>
    <item>
      <title>Top 10 values for each field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Top-10-values-for-each-field-value/m-p/360249#M106508</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a data that contains the field 'regression_target'. I want to get the top 10 rows by 'regression_tests' field.&lt;BR /&gt;
for example, if I have 4 values of 'regression_target' field, I would like to get 40 rows in my new table. 10 rows for the first value of 'regression_target', which they are the top 10 of the field 'regression_tests'.&lt;/P&gt;

&lt;P&gt;Let me know if I am not clear enough.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:42:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Top-10-values-for-each-field-value/m-p/360249#M106508</guid>
      <dc:creator>matansocher</dc:creator>
      <dc:date>2020-09-29T16:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Top 10 values for each field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Top-10-values-for-each-field-value/m-p/360250#M106509</link>
      <description>&lt;P&gt;Hi matansocher,&lt;BR /&gt;
I hope to correctly understand: if you have data in two different indexes, try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=my_index1 [seach index=my_index2 | dedup regression_target | rename regression_target  AS regression_tests| fields regression_tests ]
| top count BY regression_tests
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you ave data in the same index use it in both the searches.&lt;/P&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 09:51:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Top-10-values-for-each-field-value/m-p/360250#M106509</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2017-11-12T09:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Top 10 values for each field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Top-10-values-for-each-field-value/m-p/360251#M106510</link>
      <description>&lt;P&gt;Hi Giuseppe, thanks for your reply.&lt;BR /&gt;
I am not sure you fully understood me.&lt;BR /&gt;
let say that is the table from my index&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;regression_target|regression_tests
aaa|500
bbb|200
aaa|700
ccc|600
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and many more rows...&lt;/P&gt;

&lt;P&gt;I need to get the top 10 rows (by the 'regression_tests' field) for each value of 'regression_target' field.&lt;BR /&gt;
for example, if I have 3 values of 'regression_target' field, I would like to get 30 rows in my new table.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:42:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Top-10-values-for-each-field-value/m-p/360251#M106510</guid>
      <dc:creator>matansocher</dc:creator>
      <dc:date>2020-09-29T16:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Top 10 values for each field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Top-10-values-for-each-field-value/m-p/360252#M106511</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/217544"&gt;@matansocher&lt;/a&gt;, following is a run anywhere example which generates a mock series of 8 value per regression_target. sort and retains unique regression_test values using &lt;CODE&gt;values()&lt;/CODE&gt; statistical function. It then counts the values per series using &lt;CODE&gt;streamstats&lt;/CODE&gt; after reversing the series (or sort descending). Finally filters top 3 values for each series using &lt;CODE&gt;where&lt;/CODE&gt; condition.&lt;/P&gt;

&lt;P&gt;PS: Commands until &lt;CODE&gt;| table&lt;/CODE&gt; generate mock data as per question. You can hook in your base search instead. Also change where &lt;CODE&gt;counter&amp;lt;=3&lt;/CODE&gt; with &lt;CODE&gt;10&lt;/CODE&gt; as per your use case.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval data="bbb|770;ccc|870;bbb|970;ccc|780;aaa|780;bbb|670;ccc|950;aaa|320;bbb|230;ccc|345;aaa|500;bbb|200;ccc|600;aaa|200;bbb|150;ccc|300;aaa|800;bbb|600;aaa|400;ccc|900;bbb|200;aaa|300;ccc|400;aaa|900;bbb|800;ccc|600"
|  makemv data delim=";"
|  mvexpand data
|  eval data=split(data,"|")
|  eval regression_target=mvindex(data,0)
|  eval regression_tests=mvindex(data,1)
|  table regression_target regression_tests
|  stats values(regression_tests) as regression_tests by regression_target
|  mvexpand regression_tests
|  reverse
|  streamstats count as counter by regression_target
|  where counter&amp;lt;=3
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:46:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Top-10-values-for-each-field-value/m-p/360252#M106511</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T16:46:05Z</dc:date>
    </item>
  </channel>
</rss>

