<?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: Returning a computed expression in a subsearch in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50503#M12129</link>
    <description>&lt;P&gt;It's simpler than you think:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ ID=* error | eval search="( ID=".ID." error ) OR ( accessID=".ID." type=access )" | fields search ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and that's it. You don't need the stats or mvjoin, as the subsearch takes care of that. The trick is that the field has to be named either &lt;CODE&gt;search&lt;/CODE&gt; or &lt;CODE&gt;query&lt;/CODE&gt; for Splunk to just return the string.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;There is some weird behavior with quoting of terms though with subsearch, so the &lt;CODE&gt;return&lt;/CODE&gt; command is a lot more reliable. You can actually just copy and register the &lt;CODE&gt;return.py&lt;/CODE&gt; command from a newer version of Splunk into yours and it should work fine. In that case:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ ID=* error | eval search="( ID=".ID." error ) OR ( accessID=".ID." type=access )" | return 10000 $search ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will be more reliable.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Mar 2013 21:45:13 GMT</pubDate>
    <dc:creator>gkanapathy</dc:creator>
    <dc:date>2013-03-04T21:45:13Z</dc:date>
    <item>
      <title>Returning a computed expression in a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50501#M12127</link>
      <description>&lt;P&gt;I am using a subsearch to build part of a query.  The query is complex so I need to build the search that I want and then return it.  (We have not yet upgraded to a version that has the return command.)  I can return the entire expression, but Splunk thinks it is a string and does a search againt the string and not the value of the string.  I can also return the temp variable equal to the expression, but that is not what I want either.  Here is an idea of what I am doing:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ search ID="*" error
  | eval search="( ID=".ID." error ) OR ( accessID=".ID." type=access "
  | stats values(search) as searches
  | eval NewSearch=mvjoin(searches," OR ")
  | ???? NewSearch
] | ....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am using &lt;A href="http://splunk-base.splunk.com/answers/75786/use-input-file-to-create-a-search-and-use-a-match-command"&gt;this example&lt;/A&gt; as a guide.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2013 20:31:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50501#M12127</guid>
      <dc:creator>fk319</dc:creator>
      <dc:date>2013-03-04T20:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a computed expression in a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50502#M12128</link>
      <description>&lt;P&gt;Try &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ search ID="*" error 
  | dedup ID
  | eval search="( ID=".ID." errror ) OR ( accessID=".ID." type=access )" 
  | stats values(search) as searches 
  | eval search=mvjoin(searches," OR ") 
  | fields search
  | format "" "" "" "" "" ""
]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For every ID we find we create a field called search that looks like :&lt;/P&gt;

&lt;P&gt;( ID=xxxxx error ) OR ( accessID=xxxxx type=access )&lt;/P&gt;

&lt;P&gt;Then we join them all together with an " OR "&lt;/P&gt;

&lt;P&gt;Then we return the "search" field with special formating so the result is returned as is.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Note:&lt;/STRONG&gt; &lt;/P&gt;

&lt;P&gt;the field "search" is special when used in conjunction with format.&lt;/P&gt;

&lt;P&gt;compare :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* earliest=-60m | dedup sourcetype | stats values(sourcetype) as sourcetypes| eval wibble=mvjoin(sourcetypes," OR ") | fields wibble | format "" "" "" "" "" ""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* earliest=-60m | dedup sourcetype | stats values(sourcetype) as sourcetypes| eval search=mvjoin(sourcetypes," OR ") | fields search | format "" "" "" "" "" ""
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Mar 2013 21:22:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50502#M12128</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-03-04T21:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a computed expression in a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50503#M12129</link>
      <description>&lt;P&gt;It's simpler than you think:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ ID=* error | eval search="( ID=".ID." error ) OR ( accessID=".ID." type=access )" | fields search ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and that's it. You don't need the stats or mvjoin, as the subsearch takes care of that. The trick is that the field has to be named either &lt;CODE&gt;search&lt;/CODE&gt; or &lt;CODE&gt;query&lt;/CODE&gt; for Splunk to just return the string.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;There is some weird behavior with quoting of terms though with subsearch, so the &lt;CODE&gt;return&lt;/CODE&gt; command is a lot more reliable. You can actually just copy and register the &lt;CODE&gt;return.py&lt;/CODE&gt; command from a newer version of Splunk into yours and it should work fine. In that case:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ ID=* error | eval search="( ID=".ID." error ) OR ( accessID=".ID." type=access )" | return 10000 $search ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will be more reliable.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2013 21:45:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50503#M12129</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2013-03-04T21:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a computed expression in a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50504#M12130</link>
      <description>&lt;P&gt;On 5.X the subsearch evaluates to just the 1st row returned. &lt;/P&gt;

&lt;P&gt;i.e.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;* [ search sourcetype=* | eval search="( sourcetype=".sourcetype." error ) OR ( sourcetype=".sourcetype." type=access )" | fields search ]&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Evaluates to :&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;Subsearch evaluated to the following search expression: ( sourcetype=multline error ) OR ( sourcetype=multline type=access )&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;There's more than 1 sourcetype : &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;sourcetype=* | stats dc(sourcetype)&lt;/CODE&gt;   =   4&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2013 00:05:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50504#M12130</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-03-05T00:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a computed expression in a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50505#M12131</link>
      <description>&lt;P&gt;whereas the complete set of sourcetypes is :&lt;/P&gt;

&lt;P&gt;Subsearch evaluated to the following search expression: "( sourcetype=multiline errror ) OR ( sourcetype=multiline type=access ) OR ( sourcetype=multline errror ) OR ( sourcetype=multline type=access ) OR ( sourcetype=syslog errror ) OR ( sourcetype=syslog type=access ) OR ( sourcetype=tcp-raw errror ) OR ( sourcetype=tcp-raw type=access )"&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2013 00:06:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50505#M12131</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-03-05T00:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a computed expression in a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50506#M12132</link>
      <description>&lt;P&gt;the first is returning:&lt;BR /&gt;
wibble="(ID=xxxxx error)OR(accessID=xxxxx type=access)"&lt;BR /&gt;
and the second is returning:&lt;BR /&gt;
"(ID=xxxxx error)OR(accessID=xxxxx type=access)"&lt;BR /&gt;
what I want is:&lt;BR /&gt;
(ID=xxxxx error)OR(accessID=xxxxx type=access)&lt;/P&gt;

&lt;P&gt;I want to evaluate the expression and not compare against it.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2013 13:51:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50506#M12132</guid>
      <dc:creator>fk319</dc:creator>
      <dc:date>2013-03-05T13:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Returning a computed expression in a subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50507#M12133</link>
      <description>&lt;P&gt;When I use search, I just get the first instance.  When I use different variable, I get them all.  This is what I did to get it to work:&lt;/P&gt;

&lt;P&gt;[ search ID="*" error&lt;BR /&gt;
  | eval sch="( ID=".ID." error ) OR ( accessID=".ID." type=access "&lt;BR /&gt;
  | stats values(sch) as searches&lt;BR /&gt;
  | eval search=mvjoin(searches," OR ")&lt;BR /&gt;
  | fields search&lt;BR /&gt;
] | ....&lt;/P&gt;

&lt;P&gt;Thanks for your help...&lt;/P&gt;</description>
      <pubDate>Tue, 05 Mar 2013 14:34:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Returning-a-computed-expression-in-a-subsearch/m-p/50507#M12133</guid>
      <dc:creator>fk319</dc:creator>
      <dc:date>2013-03-05T14:34:11Z</dc:date>
    </item>
  </channel>
</rss>

