<?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: Using the value of a subsearch in main search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478481#M134195</link>
    <description>&lt;P&gt;Then you don't need to format, you can filter main search like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| search c_ip=[search &amp;lt;subsearch_query&amp;gt; | stats sum(bytes_out) as "Total Bytes Out" by c_ip | sort -"Total Bytes Out" | return $c_ip ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 24 Feb 2020 15:27:33 GMT</pubDate>
    <dc:creator>manjunathmeti</dc:creator>
    <dc:date>2020-02-24T15:27:33Z</dc:date>
    <item>
      <title>Using the value of a subsearch in main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478476#M134190</link>
      <description>&lt;P&gt;I am trying to create a search that gets the top value of a search and saves it to a variable:&lt;/P&gt;

&lt;P&gt;| eval top=[| eval MB_in=bytes_in/1024/1024 |  stats sum(MB_in) by c_ip |  rename sum(MB_in) as "Total Megabytes in" |  sort -"Total Megabytes in"  | head 1  | eval topval=c_ip | return $topval]&lt;/P&gt;

&lt;P&gt;I want to then use this value in the main search.&lt;/P&gt;

&lt;P&gt;This is currently returning the following error:&lt;BR /&gt;
Error in 'eval' command: Failed to parse the provided arguments. Usage: eval dest_key = expression.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:20:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478476#M134190</guid>
      <dc:creator>tomscott21</dc:creator>
      <dc:date>2020-09-30T04:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a subsearch in main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478477#M134191</link>
      <description>&lt;P&gt;Value should be returned from a sub-search. Change your query to:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval top=[search &amp;lt;subsearch_query&amp;gt;| eval MB_in=bytes_out/1024/1024 | stats sum(MB_in) by c_ip | rename sum(MB_in) as "Total Megabytes Out" | sort -"Total Megabytes Out" | head 1 | eval topval=c_ip | return $topval]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you are using top to filter base search results, then you can do this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;base_search&amp;gt; top=[search &amp;lt;subsearch_query&amp;gt;| eval MB_in=bytes_out/1024/1024 | stats sum(MB_in) by c_ip | rename sum(MB_in) as "Total Megabytes Out" | sort -"Total Megabytes Out" | head 1 | eval topval=c_ip | return $topval]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Feb 2020 13:53:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478477#M134191</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2020-02-24T13:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a subsearch in main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478478#M134192</link>
      <description>&lt;P&gt;I have run the first search, I am now being returned with the error "Error in 'eval' command: The number is invalid.", what does this mean?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 14:07:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478478#M134192</guid>
      <dc:creator>tomscott21</dc:creator>
      <dc:date>2020-02-24T14:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a subsearch in main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478479#M134193</link>
      <description>&lt;P&gt;It's type of the value is string then you need to format it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval top=[search | eval MB_in=bytes_out/1024/1024 | stats sum(MB_in) by c_ip | rename sum(MB_in) as "Total Megabytes Out" | sort -"Total Megabytes Out" | head 1 | eval topval=c_ip | return $topval | format ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;you can simplify this query. Return command returns first row value by default.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval top=[search &amp;lt;subsearch_query&amp;gt; | stats sum(bytes_out) as "Total Bytes Out" by c_ip | sort -"Total Bytes Out" | return $c_ip | format ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Feb 2020 14:55:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478479#M134193</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2020-02-24T14:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a subsearch in main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478480#M134194</link>
      <description>&lt;P&gt;Amazing, so I now have a field called top in my main search - this is an IP. I am now trying to use this top value to filter the c_ip field. I have done this by searching for |search c_ip=top. This in not returning any results. am i filtering this in the correct way?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:20:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478480#M134194</guid>
      <dc:creator>tomscott21</dc:creator>
      <dc:date>2020-09-30T04:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a subsearch in main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478481#M134195</link>
      <description>&lt;P&gt;Then you don't need to format, you can filter main search like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| search c_ip=[search &amp;lt;subsearch_query&amp;gt; | stats sum(bytes_out) as "Total Bytes Out" by c_ip | sort -"Total Bytes Out" | return $c_ip ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Feb 2020 15:27:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478481#M134195</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2020-02-24T15:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using the value of a subsearch in main search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478482#M134196</link>
      <description>&lt;P&gt;You are the splunk god, thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 15:48:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-value-of-a-subsearch-in-main-search/m-p/478482#M134196</guid>
      <dc:creator>tomscott21</dc:creator>
      <dc:date>2020-02-24T15:48:42Z</dc:date>
    </item>
  </channel>
</rss>

