<?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: Syntax for 'top x entries per y' in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70375#M17608</link>
    <description>&lt;P&gt;This is close but it only limits on the Y value. For example I'm only interested in the top c_ip entries (those with the highest count of events).&lt;/P&gt;</description>
    <pubDate>Tue, 25 Sep 2012 23:46:31 GMT</pubDate>
    <dc:creator>timbCFCA</dc:creator>
    <dc:date>2012-09-25T23:46:31Z</dc:date>
    <item>
      <title>Syntax for 'top x entries per y'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70372#M17605</link>
      <description>&lt;P&gt;I am trying to find the top 5 UrlDestHosts per IP address for the top 25 ip addresses. I have a search which returns the raw information required:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="windows_snare_foreweb" cs_network="Internal" action="Allowed" | stats count by c_ip, UrlDestHost | stats list(UrlDestHost) list(count) by c_ip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How do I add top parameters, say the top X c_ip entries (based on count) and the top Y UrlDestHosts (based on the count per value of X)? &lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2012 15:14:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70372#M17605</guid>
      <dc:creator>timbCFCA</dc:creator>
      <dc:date>2012-09-25T15:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for 'top x entries per y'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70373#M17606</link>
      <description>&lt;P&gt;You want to use the top search command in place of the first stats command.   Top does the count similarly to stats (also percentage)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | top 5 UrlDestHost by c_ip | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;All together it looks like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="windows_snare_foreweb" cs_network="Internal" action="Allowed" | top UrlDestHost by c_ip | stats list(UrlDestHost) list(count) by c_ip
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Sep 2012 17:41:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70373#M17606</guid>
      <dc:creator>melting</dc:creator>
      <dc:date>2012-09-25T17:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for 'top x entries per y'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70374#M17607</link>
      <description>&lt;P&gt;I think the quickest way to answer the first part of your question is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="windows_snare_foreweb" cs_network="Internal" action="Allowed" | top limit=5 UrlDestHost by c_ip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can change the limit parameter to be whatever you want; default is 10 if you remove it from the search. One of the fields returned will be percent which will probably play with your mind a bit or anyone you might show the results to so I would get rid of it. It probably also makes sense to group by c_ip. I'd probably format the query like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="windows_snare_foreweb" cs_network="Internal" action="Allowed" | top limit=5 UrlDestHost by c_ip | sort c_ip, -count | fields - percent
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will sort the IPs in ascending order, the counts in descending order, and remove the percent fields. Otherwise you could leave the query as is and use a combination of sort and head to get top results. You are also using list(). In this or other use cases use cases you might try values() which will dedup and order the results.&lt;/P&gt;

&lt;P&gt;I can't quite tell if below your code snippet if you are asking a variation of your first question. At any rate I hope some of this helps.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2012 17:45:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70374#M17607</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2012-09-25T17:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for 'top x entries per y'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70375#M17608</link>
      <description>&lt;P&gt;This is close but it only limits on the Y value. For example I'm only interested in the top c_ip entries (those with the highest count of events).&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2012 23:46:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70375#M17608</guid>
      <dc:creator>timbCFCA</dc:creator>
      <dc:date>2012-09-25T23:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for 'top x entries per y'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70376#M17609</link>
      <description>&lt;P&gt;Top is just counting events.  It can count them in categories using the "by" indication.  &lt;/P&gt;

&lt;P&gt;Perhaps you can give an example of what your output would look like?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2012 23:50:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70376#M17609</guid>
      <dc:creator>melting</dc:creator>
      <dc:date>2012-09-25T23:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for 'top x entries per y'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70377#M17610</link>
      <description>&lt;P&gt;I think you might have to resort to a subsearch for this (indented for readability);&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="windows_snare_foreweb" cs_network="Internal" action="Allowed" 
[search source="windows_snare_foreweb" cs_network="Internal" action="Allowed" 
  | top 25 c_ip 
  | fields + c_ip
] 
| top 5 UrlDestHost by c_ip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The subsearch will just find (and return) the 25 most common &lt;CODE&gt;c_ip&lt;/CODE&gt;, which are added to the outer search (as &lt;CODE&gt;c_ip1 OR c_ip2 OR c_ip3&lt;/CODE&gt; ...). The result is then piped to &lt;CODE&gt;top&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Hope this helps,&lt;/P&gt;

&lt;P&gt;Kristian&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2012 07:49:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70377#M17610</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-09-26T07:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax for 'top x entries per y'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70378#M17611</link>
      <description>&lt;P&gt;index=* sourcetype=&lt;EM&gt;iis&lt;/EM&gt; | top 1 _raw by index&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 20:14:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Syntax-for-top-x-entries-per-y/m-p/70378#M17611</guid>
      <dc:creator>maniishpawar</dc:creator>
      <dc:date>2017-07-11T20:14:01Z</dc:date>
    </item>
  </channel>
</rss>

