<?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 does subsearch work? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-does-subsearch-work/m-p/314410#M94119</link>
    <description>&lt;P&gt;Is it possible to create a new search based off of results of previous search.  My example below I use regex to extract a new column with all my users names that are extracted from User. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="source1" source="event-source"  rex field=_raw "(:?string1=\")(?&amp;lt;User&amp;gt;.*)(:?user account\")" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My goal would be to then create a new search of each user in another source&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[Pesudo EXample] index-source1 source-user-source | search User | Select Id, name, phone, etc.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 31 Aug 2017 14:23:59 GMT</pubDate>
    <dc:creator>AHEARNJ</dc:creator>
    <dc:date>2017-08-31T14:23:59Z</dc:date>
    <item>
      <title>How does subsearch work?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-subsearch-work/m-p/314410#M94119</link>
      <description>&lt;P&gt;Is it possible to create a new search based off of results of previous search.  My example below I use regex to extract a new column with all my users names that are extracted from User. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="source1" source="event-source"  rex field=_raw "(:?string1=\")(?&amp;lt;User&amp;gt;.*)(:?user account\")" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My goal would be to then create a new search of each user in another source&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[Pesudo EXample] index-source1 source-user-source | search User | Select Id, name, phone, etc.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Aug 2017 14:23:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-subsearch-work/m-p/314410#M94119</guid>
      <dc:creator>AHEARNJ</dc:creator>
      <dc:date>2017-08-31T14:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: How does subsearch work?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-subsearch-work/m-p/314411#M94120</link>
      <description>&lt;P&gt;Yes, this is very common.  You do it with a &lt;CODE&gt;subsearch&lt;/CODE&gt;:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/latest/Search/Aboutsubsearches"&gt;http://docs.splunk.com/Documentation/SplunkCloud/latest/Search/Aboutsubsearches&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 14:43:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-subsearch-work/m-p/314411#M94120</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-31T14:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: How does subsearch work?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-subsearch-work/m-p/314412#M94121</link>
      <description>&lt;P&gt;It looks something like this ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index-source1 source="user-source" 
       [ search index="source1" source="event-source" 
        | rex field=_raw "(:?string1=\")(?&amp;lt;User&amp;gt;.*)(:?user account\")" 
        | table User
       ]
 | table Id, name, phone, etc.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To see why this works, you should look at the &lt;CODE&gt;format&lt;/CODE&gt; command.  It takes all the events from the search and puts them into a field called &lt;CODE&gt;search&lt;/CODE&gt; in this format &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  ( ( User="firstUserValue" ) OR ( User="secondUserValue" ) OR ... )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To see what that looks like, run this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   index="source1" source="event-source" 
   | rex field=_raw "(:?string1=\")(?&amp;lt;User&amp;gt;.*)(:?user account\")" 
   | table User
   | format
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...and then just remember that anything in square brackets is run first and returned that way. If at the end of the square brackets there is only a field named search, then it is returned as-is.  If not, then the format command is implicitly run to convert the records to a single return field named &lt;CODE&gt;search&lt;/CODE&gt;.  &lt;/P&gt;

&lt;P&gt;(There are also a couple of other possibilities, like using the &lt;CODE&gt;return&lt;/CODE&gt; verb, but those are what matter for your question here.)&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 23:17:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-subsearch-work/m-p/314412#M94121</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-31T23:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: How does subsearch work?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-subsearch-work/m-p/314413#M94122</link>
      <description>&lt;P&gt;What he said.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 00:17:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-subsearch-work/m-p/314413#M94122</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-09-01T00:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: How does subsearch work?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-subsearch-work/m-p/314414#M94123</link>
      <description>&lt;P&gt;Thanks for such a detailed response. I really appreciate the explanation. &lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 02:33:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-subsearch-work/m-p/314414#M94123</guid>
      <dc:creator>AHEARNJ</dc:creator>
      <dc:date>2017-09-01T02:33:16Z</dc:date>
    </item>
  </channel>
</rss>

