<?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: pass a subsearch result to the head command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273419#M82433</link>
    <description>&lt;P&gt;Hi MuS&lt;BR /&gt;
With your query both the base search and the subsearch returns the same count, hence the head value returned is not divided by 2.&lt;/P&gt;

&lt;P&gt;Regards&lt;BR /&gt;
Peter&lt;/P&gt;</description>
    <pubDate>Wed, 16 Dec 2015 02:53:55 GMT</pubDate>
    <dc:creator>proylea</dc:creator>
    <dc:date>2015-12-16T02:53:55Z</dc:date>
    <item>
      <title>pass a subsearch result to the head command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273417#M82431</link>
      <description>&lt;P&gt;I am trying to pass the numeric result of a subsearch to the head command with no success, can anyone see what I am doing wrong?&lt;/P&gt;

&lt;P&gt;The following query returns a count of 3&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=starx error | fieldformat count=count/2 | stats count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to use that query as a subsearch result for the head command like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=starx error | head [ search index=starx error | fieldformat count=count/2 | stats count ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But get no result found&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2015 01:36:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273417#M82431</guid>
      <dc:creator>proylea</dc:creator>
      <dc:date>2015-12-16T01:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: pass a subsearch result to the head command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273418#M82432</link>
      <description>&lt;P&gt;Hi proylea,&lt;/P&gt;

&lt;P&gt;if you want to pass a value to the &lt;CODE&gt;head&lt;/CODE&gt; command you must return only a value form the subsearch, but you're currently returning &lt;CODE&gt;count=somenumber&lt;/CODE&gt;. Do get back only a value from the subsearch run this run everywhere search &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index=_internal error | head [ search index=_internal error | stats count | rename count AS search ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will rename the &lt;CODE&gt;count&lt;/CODE&gt; field to a &lt;CODE&gt;search&lt;/CODE&gt; field, which will just come back as a value. This way &lt;CODE&gt;head&lt;/CODE&gt; can use it.&lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2015 02:13:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273418#M82432</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-12-16T02:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: pass a subsearch result to the head command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273419#M82433</link>
      <description>&lt;P&gt;Hi MuS&lt;BR /&gt;
With your query both the base search and the subsearch returns the same count, hence the head value returned is not divided by 2.&lt;/P&gt;

&lt;P&gt;Regards&lt;BR /&gt;
Peter&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2015 02:53:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273419#M82433</guid>
      <dc:creator>proylea</dc:creator>
      <dc:date>2015-12-16T02:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: pass a subsearch result to the head command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273420#M82434</link>
      <description>&lt;P&gt;Sorry my bad, ignore the second example. Look at the provided first example and tweak it to your needs.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2015 03:06:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273420#M82434</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-12-16T03:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: pass a subsearch result to the head command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273421#M82435</link>
      <description>&lt;P&gt;Cheers, I still can't work out how to divide the count by 2 to return the result?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2015 03:11:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273421#M82435</guid>
      <dc:creator>proylea</dc:creator>
      <dc:date>2015-12-16T03:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: pass a subsearch result to the head command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273422#M82436</link>
      <description>&lt;P&gt;Finally got it!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=starx error | head [ search index=starx error | stats count | eval total=round(count/2) | rename total AS search ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Dec 2015 03:25:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273422#M82436</guid>
      <dc:creator>proylea</dc:creator>
      <dc:date>2015-12-16T03:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: pass a subsearch result to the head command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273423#M82437</link>
      <description>&lt;P&gt;Thanks for your help MuS with the rename AS search&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2015 03:26:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273423#M82437</guid>
      <dc:creator>proylea</dc:creator>
      <dc:date>2015-12-16T03:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: pass a subsearch result to the head command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273424#M82438</link>
      <description>&lt;P&gt;If you want to avoid using a subsearch altogether you could do something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=starx error | streamstats count as total_results | eventstats p50(count) as average | eval keep=count-average | search keep&amp;gt;0 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This avoids any limitations in the subsearch if your index is very large, and saves you from running the index=starx search twice. &lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2015 12:44:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/pass-a-subsearch-result-to-the-head-command/m-p/273424#M82438</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2015-12-16T12:44:45Z</dc:date>
    </item>
  </channel>
</rss>

