<?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 subset top N records from the number generated from eventstats in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294694#M88926</link>
    <description>&lt;P&gt;I figured out another way to realize my need. &lt;BR /&gt;
Basically, by leveraging the "sub-search" to extract and return the orgID with the top N value of stat2, and use the result of sub-search as the filter criteria to the primary search query. &lt;BR /&gt;
For sub-search, pls refer here: &lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/Search/Aboutsubsearches"&gt;http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/Search/Aboutsubsearches&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Oct 2017 23:38:14 GMT</pubDate>
    <dc:creator>zztc2004</dc:creator>
    <dc:date>2017-10-12T23:38:14Z</dc:date>
    <item>
      <title>How to subset top N records from the number generated from eventstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294688#M88920</link>
      <description>&lt;P&gt;Hi Splunk friends, &lt;/P&gt;

&lt;P&gt;I am new to Splunk community and currently facing a question. &lt;BR /&gt;
I have below table which was generated by some raw log-line data . &lt;BR /&gt;
stats2 is actually the aggregated sum of stats1 group by ID.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ID  stat1   stats2(eventstats sum of stat1 by ID)
1   1          6
1   2          6
1   3          6
2   4          9
2   5          9
3   6          21
3   7          21
3   8          21
4   9          10
4   0          10
4   1          10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I am looking for is, returning the subset of below table and only pick top N =2  in terms of stats2, for example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ID  stat1   stats2(eventstats sum of stat1 by ID)
3      6       21
3      7       21
3.     8       21
4      9       10
4      0       10
4      1       10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried several methods that all failed, and I do not want to leverage join statement, which is not efficient in Splunk. &lt;/P&gt;

&lt;P&gt;Thanks so much for the help.&lt;BR /&gt;
Jay&lt;/P&gt;</description>
      <pubDate>Wed, 11 Oct 2017 23:44:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294688#M88920</guid>
      <dc:creator>zztc2004</dc:creator>
      <dc:date>2017-10-11T23:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset top N records from the number generated from eventstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294689#M88921</link>
      <description>&lt;P&gt;Here's one way &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  your query
 | appendpipe [| dedup stats2 | sort 2 - stats2 | table stats2 | eval keepme="Y"]
 | eventstats values(keepme) as keepme by stats2 
 | where isnotnull(keepme) and isnotnull(stats1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Of course, it would be more efficient to, instead of &lt;CODE&gt;| eventstats&lt;/CODE&gt; to calculate stats2, to do the &lt;CODE&gt;appendpipe&lt;/CODE&gt; strategy and summarize by ID directly, keeping the top 2. &lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 00:53:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294689#M88921</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-10-12T00:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset top N records from the number generated from eventstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294690#M88922</link>
      <description>&lt;P&gt;if I understand it correctly,  you want rows with top 2 stats2 values right?&lt;/P&gt;

&lt;P&gt;some thing like this should work.  replace regexes or eval x= expression based on your data.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| eval x=ID+":"+stat1 | stats list(x) as x by stats2 | sort - stats2 | head 2 | mvexpand x | rex field=x "(?&amp;lt;ID&amp;gt;[^\:]+)\:(?&amp;lt;stat1&amp;gt;.+)" | fields - x&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 00:56:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294690#M88922</guid>
      <dc:creator>kyaparla</dc:creator>
      <dc:date>2017-10-12T00:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset top N records from the number generated from eventstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294691#M88923</link>
      <description>&lt;P&gt;Thanks, this appendpipe is very helpful for my case!&lt;/P&gt;

&lt;P&gt;Jay&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 02:21:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294691#M88923</guid>
      <dc:creator>zztc2004</dc:creator>
      <dc:date>2017-10-12T02:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset top N records from the number generated from eventstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294692#M88924</link>
      <description>&lt;P&gt;@kayaparla - nice.  That would work.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 05:00:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294692#M88924</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-10-12T05:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset top N records from the number generated from eventstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294693#M88925</link>
      <description>&lt;P&gt;Hi @DalJeanis,&lt;/P&gt;

&lt;P&gt;Any idea, why I got error when I try to use sort within appendpipe[]?&lt;BR /&gt;
So confused....&lt;/P&gt;

&lt;P&gt;Jay&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 21:31:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294693#M88925</guid>
      <dc:creator>zztc2004</dc:creator>
      <dc:date>2017-10-12T21:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to subset top N records from the number generated from eventstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294694#M88926</link>
      <description>&lt;P&gt;I figured out another way to realize my need. &lt;BR /&gt;
Basically, by leveraging the "sub-search" to extract and return the orgID with the top N value of stat2, and use the result of sub-search as the filter criteria to the primary search query. &lt;BR /&gt;
For sub-search, pls refer here: &lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/Search/Aboutsubsearches"&gt;http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/Search/Aboutsubsearches&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 23:38:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-subset-top-N-records-from-the-number-generated-from/m-p/294694#M88926</guid>
      <dc:creator>zztc2004</dc:creator>
      <dc:date>2017-10-12T23:38:14Z</dc:date>
    </item>
  </channel>
</rss>

