<?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 use top command (or stats with sort) results with another top command or subsearch? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/218105#M64114</link>
    <description>&lt;P&gt;If you have always four records finally ie 2 websites * 2 users , try this .&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search&amp;gt; |table user website |top limit=2 user by website|head 4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It can't be that simple i believe. I should be missing something &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jan 2016 12:21:39 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2016-01-08T12:21:39Z</dc:date>
    <item>
      <title>How to use top command (or stats with sort) results with another top command or subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/218102#M64111</link>
      <description>&lt;P&gt;Hello all, &lt;/P&gt;

&lt;P&gt;I'm trying to get the stats commands to work in chain.  I have the following data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;08 January 2016 09:10:10 website=abc.com, user=user1, message=blahblah1
08 January 2016 09:10:11 website=abc.com, user=user1, message=blahblah2
08 January 2016 09:10:12 website=abc.com, user=user1, message=blahblah2x
08 January 2016 09:10:13 website=abc.com, user=user1, message=blahblah2xxx
08 January 2016 09:10:14 website=abc.com, user=user1, message=blahblah2xxx
08 January 2016 09:10:15 website=abc.com, user=user1, message=blahblah2xxxxx
08 January 2016 09:10:16 website=abc.com, user=user2, message=blahblah3x
08 January 2016 09:10:17 website=abc.com, user=user2, message=blahblah3xx
08 January 2016 09:10:18 website=abc.com, user=user2, message=blahblah3
08 January 2016 09:10:19 website=abc.com, user=user3, message=blahblah4
08 January 2016 09:10:20 website=def.com, user=user1, message=blahblah5
08 January 2016 09:10:21 website=def.com, user=user2, message=blahblah6
08 January 2016 09:10:22 website=def.com, user=user2, message=blahblah7
08 January 2016 09:10:23 website=def.com, user=user2, message=blahblah8
08 January 2016 09:10:24 website=xyz.com, user=user3, message=blahblah9
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And I want to get the Top 2 websites listing for only Top 2 users per website; hence the following table output is what I'm trying to get:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Website User
abc.com user1
abc.com user2
def.com user2
def.com user1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I was looking into foreach command, but that does not allow me to use top/stats. E.g:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;… | top limit=2 website | foreach website [ search website=&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; | top limit=2 user ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I’d appreciate any feedback.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 11:50:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/218102#M64111</guid>
      <dc:creator>selim</dc:creator>
      <dc:date>2016-01-08T11:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to use top command (or stats with sort) results with another top command or subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/218103#M64112</link>
      <description>&lt;P&gt;I would use a subsearch:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# Top websites for top 2 users
yoursearch [ yoursearch | top limit=2 user | table user]
| top limit=0 website, user

# Top users for top 2 websites
yoursearch [ yoursearch | top limit=2 website | table website]
| top limit=0 website, user
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jan 2016 11:59:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/218103#M64112</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-01-08T11:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use top command (or stats with sort) results with another top command or subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/218104#M64113</link>
      <description>&lt;P&gt;Thank you javiergn.  This helped me find out the solution as the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;mysearchstring  [ mysearchstring | top limit=2 website | table website ] | stats count by website,user  | sort +website,-count | dedup 2 website
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;first &lt;CODE&gt;limit&lt;/CODE&gt; is for top websites and limiting the &lt;CODE&gt;dedup&lt;/CODE&gt; is for top users per website.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 12:14:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/218104#M64113</guid>
      <dc:creator>selim</dc:creator>
      <dc:date>2016-01-08T12:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to use top command (or stats with sort) results with another top command or subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/218105#M64114</link>
      <description>&lt;P&gt;If you have always four records finally ie 2 websites * 2 users , try this .&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search&amp;gt; |table user website |top limit=2 user by website|head 4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It can't be that simple i believe. I should be missing something &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 12:21:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/218105#M64114</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2016-01-08T12:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to use top command (or stats with sort) results with another top command or subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/218106#M64115</link>
      <description>&lt;P&gt;I wanted to add another quick comment on the solution.  The one I put up there did not properly sort the results.  I wanted the results to be grouped by websites (top websites by count or another field value, eg. bandwidth).  I tried something like the following (2 subsearches):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;mysearchstring [ mysearchstring | top limit=2 website | table website ] [search [ mysearchstring | top limit=2 website | table website ] | stats count by user | sort 2 -count| table user] | stats count by website,user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But this also does not group properly and seems costly.  In order to sort, I had to add a &lt;CODE&gt;sort_field&lt;/CODE&gt; to each event and then use that.  For this, I used &lt;CODE&gt;eventstats&lt;/CODE&gt; to compute a new field and use the average of that when evaluating &lt;CODE&gt;sort_field&lt;/CODE&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;mysearchstring  [ mysearchstring | top limit=2 website | table website ] | eventstats count AS sortcount by website | stats count, avg(sortcount) AS sort_field by website,user  | dedup 2 website | sort -sort_field | fields website, user
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Jan 2016 16:09:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/218106#M64115</guid>
      <dc:creator>selim</dc:creator>
      <dc:date>2016-01-09T16:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to use top command (or stats with sort) results with another top command or subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/557977#M158468</link>
      <description>&lt;P&gt;| makeresults&lt;BR /&gt;| eval data="&lt;BR /&gt;08 January 2016 09:10:10 website=abc.com, user=user1, message=blahblah1;&lt;BR /&gt;08 January 2016 09:10:11 website=abc.com, user=user1, message=blahblah2;&lt;BR /&gt;08 January 2016 09:10:12 website=abc.com, user=user1, message=blahblah2x;&lt;BR /&gt;08 January 2016 09:10:13 website=abc.com, user=user1, message=blahblah2xxx;&lt;BR /&gt;08 January 2016 09:10:14 website=abc.com, user=user1, message=blahblah2xxx;&lt;BR /&gt;08 January 2016 09:10:15 website=abc.com, user=user1, message=blahblah2xxxxx;&lt;BR /&gt;08 January 2016 09:10:16 website=abc.com, user=user2, message=blahblah3x;&lt;BR /&gt;08 January 2016 09:10:17 website=abc.com, user=user2, message=blahblah3xx;&lt;BR /&gt;08 January 2016 09:10:18 website=abc.com, user=user2, message=blahblah3;&lt;BR /&gt;08 January 2016 09:10:19 website=abc.com, user=user3, message=blahblah4;&lt;BR /&gt;08 January 2016 09:10:20 website=def.com, user=user1, message=blahblah5;&lt;BR /&gt;08 January 2016 09:10:21 website=def.com, user=user2, message=blahblah6;&lt;BR /&gt;08 January 2016 09:10:22 website=def.com, user=user2, message=blahblah7;&lt;BR /&gt;08 January 2016 09:10:23 website=def.com, user=user2, message=blahblah8;&lt;BR /&gt;08 January 2016 09:10:24 website=xyz.com, user=user3, message=blahblah9"&lt;BR /&gt;| makemv data delim=";"&lt;BR /&gt;| mvexpand data&lt;BR /&gt;| rex field=data "(?&amp;lt;Timestamp&amp;gt;\d+\s\w+\s\d+\s\d+:\d+:\d+)\s[^\s]+=(?&amp;lt;website&amp;gt;[^\s]+),\s[^\s]+=(?&amp;lt;user&amp;gt;[^\s]+),\s[^\s]+=(?&amp;lt;message&amp;gt;[^\s]+)"&lt;BR /&gt;| table website user&lt;BR /&gt;| &lt;FONT color="#99CC00"&gt;top 2 user by website showcount=f showperc=f&lt;/FONT&gt;&lt;BR /&gt;| rename user as User, website as Website&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 05:46:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-top-command-or-stats-with-sort-results-with-another/m-p/557977#M158468</guid>
      <dc:creator>laurenceamckay</dc:creator>
      <dc:date>2021-07-01T05:46:48Z</dc:date>
    </item>
  </channel>
</rss>

