<?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: Subsearch fields &amp;quot;query&amp;quot; &amp;quot;search&amp;quot; - How do I know which to use? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62427#M15410</link>
    <description>&lt;P&gt;Amen to query!&lt;/P&gt;</description>
    <pubDate>Mon, 18 Dec 2017 21:58:30 GMT</pubDate>
    <dc:creator>walterk82</dc:creator>
    <dc:date>2017-12-18T21:58:30Z</dc:date>
    <item>
      <title>Subsearch fields "query" "search" - How do I know which to use?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62422#M15405</link>
      <description>&lt;P&gt;Can anyone explain exactly the difference between the special sub-search fields "search" and "query"?&lt;/P&gt;

&lt;P&gt;Both of these fields are mentioned in the &lt;A href="http://www.splunk.com/base/Documentation/latest/User/HowSubsearchesWork" rel="nofollow"&gt;docs&lt;/A&gt;, but I don't see anything listed about how they differ.  Any examples would be welcomed.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2010 22:03:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62422#M15405</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-10-01T22:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch fields "query" "search" - How do I know which to use?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62423#M15406</link>
      <description>&lt;H2&gt;Using "search"&lt;/H2&gt;

&lt;P&gt;It appears when you just use "search" then whatever first data is in the search field is used as the actual search term.
Example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=blah [search  index=blah host=blahadmin | rename EventCode as search]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will result in a search like such:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;litsearch index=blah 538 | fields keepcolorder=t * "*" "host" "index" "source" "sourcetype" "splunk_server"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Notice the "538" which is the first result returned in the EventCode field in the subsearch. You can also use "search" to modify the actual search string that gets passed to the outer search.&lt;/P&gt;

&lt;P&gt;For Example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=blah [search  index=blah host=blahadmin| eval search="hello there " + EventCode]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Will result in:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;litsearch index=blah hello there 538 | fields keepcolorder=t * "*" "host" "index" "source" "sourcetype" "splunk_server"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;H2&gt;Using "query"&lt;/H2&gt;

&lt;P&gt;"Query" will behave similar to format, but instead of putting out &lt;CODE&gt;(field1=foo) OR (field1=bar)&lt;/CODE&gt; will just put out the values &lt;CODE&gt;(foo) OR (bar)&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=blah [search  index=blah host=blahadmin | rename EventCode as query | fields query]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will result in a search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;litsearch index=blah ( ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 19 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 538 ) OR ( 540 ) OR ( 2000 ) OR ( 2000 ) ) | fields keepcolorder=t * "*" "host" "index" "source" "sourcetype" "splunk_server"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Of course you can &lt;CODE&gt;dedup&lt;/CODE&gt; EventCode to come up with&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;litsearch index=blah ( ( 538 ) OR ( 540 ) OR ( 10002 ) OR ( 19 ) OR ( 2000 ) OR ( 560 ) OR ( 576 ) OR ( 552 ) ) | fields keepcolorder=t * "*" "host" "index" "source" "sourcetype" "splunk_server"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;H2&gt;Normal syntax&lt;/H2&gt;

&lt;P&gt;And finally the using the regular syntax with the implied &lt;CODE&gt;format&lt;/CODE&gt; at the end of the subsearch:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=blah [search  index=blah host=blahadmin| fields EventCode]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;litsearch index=blah ( ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="10002" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) OR ( EventCode="540" ) OR ( EventCode="538" ) ) | fields keepcolorder=t * "*" "host" "index" "source" "sourcetype" "splunk_server"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Again a &lt;CODE&gt;dedup&lt;/CODE&gt; should be used here.&lt;/P&gt;

&lt;H2&gt;Conclusion&lt;/H2&gt;

&lt;P&gt;There are definitely many use cases for each of these methods. 
"&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;&lt;P&gt;Search" can come in real handy when
you need to append some static data
or do some evals on the data in your
subsearch and then pass it to the
outer search. You could build some complex logic here.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;"Query" comes in handy when you are
simply looking for the values in the
fields returned from the subsearch,
but not in these exact fields. And
regular syntax comes in handy when
you are looking for the returned
values in the returned fields.-&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;On top of all this you can use the
&lt;A href="http://www.splunk.com/base/Documentation/latest/SearchReference/Format--" rel="nofollow"&gt;format&lt;/A&gt; command to apply all
kinds of fun formatting to your
subsearch results. :)-&lt;/P&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Note: After running a search you can click the Actions menu and select "Inspect Search", scroll down to the remoteSearch field, and you can see what the actual query that ended up being built by your subsearch was.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2010 22:38:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62423#M15406</guid>
      <dc:creator>ftk</dc:creator>
      <dc:date>2010-10-01T22:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch fields "query" "search" - How do I know which to use?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62424#M15407</link>
      <description>&lt;P&gt;Thanks! The Query field has helped a lot for subsearches!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2013 21:44:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62424#M15407</guid>
      <dc:creator>martinaire</dc:creator>
      <dc:date>2013-06-12T21:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch fields "query" "search" - How do I know which to use?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62425#M15408</link>
      <description>&lt;P&gt;The tip about the query field was very handy. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Aug 2014 13:56:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62425#M15408</guid>
      <dc:creator>mikaelbje</dc:creator>
      <dc:date>2014-08-18T13:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch fields "query" "search" - How do I know which to use?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62426#M15409</link>
      <description>&lt;P&gt;You can pipe your subsearch clause to the &lt;CODE&gt;format&lt;/CODE&gt; command to see what will actually returned if you were to use the search to the left as a subsearch.  When you use &lt;CODE&gt;search&lt;/CODE&gt; you get &lt;CODE&gt;(fieldName=value)&lt;/CODE&gt; combinations coming back but when you use &lt;CODE&gt;query&lt;/CODE&gt; you get just &lt;CODE&gt;(value)&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2016 16:40:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62426#M15409</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-06-06T16:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch fields "query" "search" - How do I know which to use?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62427#M15410</link>
      <description>&lt;P&gt;Amen to query!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 21:58:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Subsearch-fields-quot-query-quot-quot-search-quot-How-do-I-know/m-p/62427#M15410</guid>
      <dc:creator>walterk82</dc:creator>
      <dc:date>2017-12-18T21:58:30Z</dc:date>
    </item>
  </channel>
</rss>

