<?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 find top 20 results and then do a subsequent search? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430867#M123164</link>
    <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=YouShouldAlwaysSpecifyAnIndex sourcetype=site_data
[search index=YouShouldAlwaysSpecifyAnIndex sourcetype=site_data
| top limit=20 "Site Name" | table "Site Name" | format]
| top limit=1 Product BY "Site Name"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 24 Jun 2019 01:33:44 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-06-24T01:33:44Z</dc:date>
    <item>
      <title>How to find top 20 results and then do a subsequent search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430864#M123161</link>
      <description>&lt;P&gt;I need to find out the Top 20 sites within my sourcetype and then from there be able to do further analysis on other fields such as Product. &lt;BR /&gt;
Are there a non-destructive stats command I can use for this?&lt;/P&gt;

&lt;P&gt;i.e.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=site_data | stats count by "Site Name" | head 20  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and then a subsequent search to find out of those twenty sites what is the top product logged?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Jack&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 08:13:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430864#M123161</guid>
      <dc:creator>jackreeves</dc:creator>
      <dc:date>2019-06-21T08:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to find top 20 results and then do a subsequent search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430865#M123162</link>
      <description>&lt;P&gt;You could use a subsearch:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=site_data [|search sourcetype=site_data | top 20 "Site Name" | fields "Site Name"] &amp;lt;put the rest of your search here&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.0/Search/Usesubsearchtocorrelateevents"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.0/Search/Usesubsearchtocorrelateevents&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 16:59:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430865#M123162</guid>
      <dc:creator>spayneort</dc:creator>
      <dc:date>2019-06-21T16:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to find top 20 results and then do a subsequent search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430866#M123163</link>
      <description>&lt;P&gt;To add on to this answer, the subsearch provided by spayneort effectively returns the top 20 "Site Name" values as 20 "OR" seperated field=value pairs. &lt;/P&gt;

&lt;P&gt;To further understand it, Splunk performs the subsearch first then essentially modifies your search to be:&lt;BR /&gt;
sourcetype=site_data "Site Name"=&lt;A href="https://url1"&gt;https://url1&lt;/A&gt; OR "Site Name"=&lt;A href="https://url2"&gt;https://url2&lt;/A&gt; OR "Site Name"=&lt;A href="http://url2"&gt;http://url2&lt;/A&gt; OR ....&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2019 20:02:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430866#M123163</guid>
      <dc:creator>danielansell</dc:creator>
      <dc:date>2019-06-21T20:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to find top 20 results and then do a subsequent search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430867#M123164</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=YouShouldAlwaysSpecifyAnIndex sourcetype=site_data
[search index=YouShouldAlwaysSpecifyAnIndex sourcetype=site_data
| top limit=20 "Site Name" | table "Site Name" | format]
| top limit=1 Product BY "Site Name"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Jun 2019 01:33:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430867#M123164</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-06-24T01:33:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to find top 20 results and then do a subsequent search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430868#M123165</link>
      <description>&lt;P&gt;P.S.  field names with spaces are &lt;EM&gt;E*V*I*L&lt;/EM&gt;!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:02:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430868#M123165</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-09-30T01:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to find top 20 results and then do a subsequent search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430869#M123166</link>
      <description>&lt;P&gt;Thanks guys this has worked as expected! Knew there must be a simple solution.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2019 07:39:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-top-20-results-and-then-do-a-subsequent-search/m-p/430869#M123166</guid>
      <dc:creator>jackreeves</dc:creator>
      <dc:date>2019-06-24T07:39:20Z</dc:date>
    </item>
  </channel>
</rss>

