<?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: Problems with subsearch and returning multiple fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Problems-with-subsearch-and-returning-multiple-fields/m-p/226530#M66803</link>
    <description>&lt;P&gt;Hi reinoheinanen, &lt;/P&gt;

&lt;P&gt;You can use the fields command in your subsearch to return a specified fields as arguments for the outer search. For example: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... [ search sourcetype="dns" "specific urls" | dedup src | fields src] ... 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are other ways you can change the format of subsearch results to meet your needs. For more information, please refer to documentation:  &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.1/Search/Changetheformatofsubsearchresults"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.1/Search/Changetheformatofsubsearchresults&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Hope this helps. Thanks! &lt;BR /&gt;
Hunter&lt;/P&gt;</description>
    <pubDate>Wed, 11 Jan 2017 14:59:56 GMT</pubDate>
    <dc:creator>hunters_splunk</dc:creator>
    <dc:date>2017-01-11T14:59:56Z</dc:date>
    <item>
      <title>Problems with subsearch and returning multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problems-with-subsearch-and-returning-multiple-fields/m-p/226529#M66802</link>
      <description>&lt;P&gt;Hello I'm trying t run the following search:&lt;/P&gt;

&lt;P&gt;Using subsearch I collect from DNS logs the source IP address and the domain they looked up.&lt;BR /&gt;
Then using the source IP address query the windows security event logs to see user using the IP address at the time.&lt;BR /&gt;
Create output with the destination, source IP, userdetails&lt;/P&gt;

&lt;P&gt;I'm having problems with subsearch and returning values. &lt;BR /&gt;
How do you return multiple fields and then search further only using one of the fields (src in this case)?&lt;/P&gt;

&lt;P&gt;[ search sourcetype="dns" "specific urls" | dedup src | return src query ]&lt;BR /&gt;
sourcetype="WinSecurityEvent" src &lt;BR /&gt;
| dedup accountname | stats values(accountname) AS accounts | table query, src, accounts&lt;/P&gt;

&lt;P&gt;Or is there better way doing this?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2017 11:57:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problems-with-subsearch-and-returning-multiple-fields/m-p/226529#M66802</guid>
      <dc:creator>reinoheinanen</dc:creator>
      <dc:date>2017-01-11T11:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with subsearch and returning multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problems-with-subsearch-and-returning-multiple-fields/m-p/226530#M66803</link>
      <description>&lt;P&gt;Hi reinoheinanen, &lt;/P&gt;

&lt;P&gt;You can use the fields command in your subsearch to return a specified fields as arguments for the outer search. For example: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... [ search sourcetype="dns" "specific urls" | dedup src | fields src] ... 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are other ways you can change the format of subsearch results to meet your needs. For more information, please refer to documentation:  &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.1/Search/Changetheformatofsubsearchresults"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.1/Search/Changetheformatofsubsearchresults&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Hope this helps. Thanks! &lt;BR /&gt;
Hunter&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2017 14:59:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problems-with-subsearch-and-returning-multiple-fields/m-p/226530#M66803</guid>
      <dc:creator>hunters_splunk</dc:creator>
      <dc:date>2017-01-11T14:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with subsearch and returning multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problems-with-subsearch-and-returning-multiple-fields/m-p/226531#M66804</link>
      <description>&lt;P&gt;Thanks Hunter,&lt;/P&gt;

&lt;P&gt;So now I have another problem. The link you provided had details about format command which I was hoping to use to modify returned search result so that it will work with multiple returned fields.&lt;/P&gt;

&lt;P&gt;Splunk docs says: &lt;BR /&gt;
"The format command changes your subsearch results into a single linear search string. This is used when you want to pass the returned values in the returned fields into the primary search."&lt;/P&gt;

&lt;P&gt;I have managed to get the query to work if I return a single field. But it doesn't work if I pipe it to format. Seem primary search doesn't work with the returned linear search string?&lt;/P&gt;

&lt;P&gt;[ search sourcetype="dns" "specific urls" | dedup src | return 3 src_ip=src | format ]&lt;BR /&gt;
sourcetype="WinSecurityEvent" &lt;BR /&gt;
| dedup accountname | stats values(accountname) AS accounts | table query, src_ip, accounts&lt;/P&gt;

&lt;P&gt;The formatted search string that is returned contains (this does not work):&lt;BR /&gt;
( ( "(src_ip=\"10.10.10.1\") OR (src_ip=\"10.10.10.2\") OR (src_ip=\"10.10.10.3\")" ) )&lt;/P&gt;

&lt;P&gt;Without format (this works):&lt;BR /&gt;
(src_ip="10.10.10.1") OR (src_ip="10.10.10.2") OR (src_ip="10.10.10.3")&lt;/P&gt;

&lt;P&gt;Is there a bug or am I missing something from my command or I'm supposed to modify linear search strings somehow before they can be used with primary search?  &lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:22:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problems-with-subsearch-and-returning-multiple-fields/m-p/226531#M66804</guid>
      <dc:creator>reinoheinanen</dc:creator>
      <dc:date>2020-09-29T12:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with subsearch and returning multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problems-with-subsearch-and-returning-multiple-fields/m-p/226532#M66805</link>
      <description>&lt;P&gt;I managed to get this to work but had to do it slightly differently. &lt;/P&gt;

&lt;P&gt;As Splunk doesn't seem to support proper control over what to do with results that are returned from sub searches I had to run two separate sub searches using OR between them.&lt;/P&gt;

&lt;P&gt;(index=winsec sourcetype="WinSecurityEvent" src [ search sourcetype="dns" "specific urls" | dedup src | return 100 src_ip=src  ] ) OR &lt;BR /&gt;
(index=DNS [ search sourcetype="dns" "specific urls" | dedup src | return 100 query ]) &lt;BR /&gt;
| dedup accountname | stats values(accountname) AS accounts | table query, src_ip, accounts&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:24:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problems-with-subsearch-and-returning-multiple-fields/m-p/226532#M66805</guid>
      <dc:creator>reinoheinanen</dc:creator>
      <dc:date>2020-09-29T12:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with subsearch and returning multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Problems-with-subsearch-and-returning-multiple-fields/m-p/516995#M145344</link>
      <description>&lt;DIV class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;I just posted an "idea" for the return command to be able to do what you would like it to do.&lt;/P&gt;&lt;P&gt;&lt;A href="https://ideas.splunk.com/ideas/EID-I-532" target="_blank" rel="noopener"&gt;https://ideas.splunk.com/ideas/EID-I-532&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The following is your command, rewritten with a rex command that should create a simple boolean expression from one subsearch.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(index=winsec sourcetype="WinSecurityEvent") OR index=DNS 
    [ search sourcetype="dns" "specific urls" 
    | dedup src 
    | return 100 src_ip=src OR query
    | eval search = if(len(search)&amp;lt;3, "NOTHING FOUND")
    | rex mode=sed field=search "s/ (OR|AND|NOT)=\"\" / \1 /g" ] ) 
| dedup accountname 
| stats values(accountname) AS accounts 
| table query, src_ip, accounts&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The string in the eval command should be changed to something that will never be found.&amp;nbsp; Depending on the use, perhaps "index!=*" might be more efficient.&amp;nbsp; Otherwise, if nothing is found then the search will return an empty string that matches all events. This may be desired, in which case the eval statement should be removed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Aug 2020 10:30:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Problems-with-subsearch-and-returning-multiple-fields/m-p/516995#M145344</guid>
      <dc:creator>malvidin</dc:creator>
      <dc:date>2020-08-31T10:30:50Z</dc:date>
    </item>
  </channel>
</rss>

