<?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 How to append search result with top 100 results? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-result-with-top-100-results/m-p/411734#M118739</link>
    <description>&lt;P&gt;I will try to explain my issue in the easiest possible way.&lt;/P&gt;

&lt;P&gt;I have a result of a search that looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;name1, name2, size
A      A      25
A      B      25
A      C      25
B      B      18
C      C      15
C      D      15
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In the real project, the search is more complex but it follow this logic: A can have multiple B and always have the size of A.&lt;/P&gt;

&lt;P&gt;I will need to retrieve the top 100 sizes but as this example is short, I would love to get the top 2 sizes and keep data from all other columns.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;name1, name2, size
A      A      25
A      B      25
A      C      25
B      B      18
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I really don't want to append this search with subsearch as search leading to this data is already very complex and takes a lot of time. &lt;BR /&gt;
Is there any simple trick on how to achieve this?&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jul 2019 13:50:27 GMT</pubDate>
    <dc:creator>seva98</dc:creator>
    <dc:date>2019-07-23T13:50:27Z</dc:date>
    <item>
      <title>How to append search result with top 100 results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-result-with-top-100-results/m-p/411734#M118739</link>
      <description>&lt;P&gt;I will try to explain my issue in the easiest possible way.&lt;/P&gt;

&lt;P&gt;I have a result of a search that looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;name1, name2, size
A      A      25
A      B      25
A      C      25
B      B      18
C      C      15
C      D      15
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In the real project, the search is more complex but it follow this logic: A can have multiple B and always have the size of A.&lt;/P&gt;

&lt;P&gt;I will need to retrieve the top 100 sizes but as this example is short, I would love to get the top 2 sizes and keep data from all other columns.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;name1, name2, size
A      A      25
A      B      25
A      C      25
B      B      18
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I really don't want to append this search with subsearch as search leading to this data is already very complex and takes a lot of time. &lt;BR /&gt;
Is there any simple trick on how to achieve this?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 13:50:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-result-with-top-100-results/m-p/411734#M118739</guid>
      <dc:creator>seva98</dc:creator>
      <dc:date>2019-07-23T13:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to append search result with top 100 results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-result-with-top-100-results/m-p/411735#M118740</link>
      <description>&lt;P&gt;@seva98,&lt;/P&gt;

&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"your search"|sort - size|eventstats list(size) size_list|eval size_list=mvdedup(size_list)
|eval hundredth=mvindex(size_list,99)
|where size &amp;gt;=hundredth | fields - size_list,hundredth
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Jul 2019 14:24:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-result-with-top-100-results/m-p/411735#M118740</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-07-23T14:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to append search result with top 100 results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-result-with-top-100-results/m-p/411736#M118741</link>
      <description>&lt;P&gt;Almost, I have another issue when two different name1 have the same size for example name1=D =&amp;gt; size=10, name1=E =&amp;gt; size=10. Unfortunatelly mvdedup count them as one.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2019 19:50:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-result-with-top-100-results/m-p/411736#M118741</guid>
      <dc:creator>seva98</dc:creator>
      <dc:date>2019-07-23T19:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to append search result with top 100 results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-result-with-top-100-results/m-p/411737#M118742</link>
      <description>&lt;P&gt;Fixed it, thanks to @renjith.nair explanation. His solution just had issue for data where multiple name1 can have same size. There may be some extra unnecessary code but it works.&lt;/P&gt;

&lt;P&gt;Sorting is done first so I get the biggest nodes at the top.&lt;BR /&gt;
Then I cut the list to desired size (97 in this case)&lt;BR /&gt;
Then I am looking if name1 is in filteredList.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval parent=if(name1=name2, 1, 0)
| sort name
| sort -size
| sort -parent
| eventstats list(name1) as uniquelist
| eval filteredlist=mvindex(uniquelist, 0, 96)
| eval find_match = if(match(name1, filteredlist), 1, 0)
| where name1=filteredlist
| fields - filteredlist, uniquelist
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jul 2019 06:14:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-append-search-result-with-top-100-results/m-p/411737#M118742</guid>
      <dc:creator>seva98</dc:creator>
      <dc:date>2019-07-24T06:14:21Z</dc:date>
    </item>
  </channel>
</rss>

