<?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 can I give source string dynamically in COLLECT command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-give-source-string-dynamically-in-COLLECT-command/m-p/436078#M124310</link>
    <description>&lt;P&gt;I want to extract a value dynamically in a subsearch and give the value (string) to source= &amp;lt;&amp;lt; string&amp;gt;&amp;gt; of COLLECT command.  The following example is extracting YYYYMMDD from the source field and making "src_yyyymmdd" string that will be given to source=&amp;lt;&amp;lt; string&amp;gt;&amp;gt;  of the COLLECT command. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    main search... | collect index="ABC" source=[search index="XYZ" 
        |head 1 | rex field=source "^FILENAME_(?&amp;lt;YYYYMMDD&amp;gt;\d{8})_.*"
        | eval fieldval="\""+"src_"+YYYYMMDD+"\""  
        | table source YYYYMMDD fieldval
        | return $fieldval]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I checked the above subsearch as a main search, every field value after table command was what I expected.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5363i43EA31FA86914124/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Unfortunately, the result was  &lt;EM&gt;Error in 'collect' command: Invalid argument: 'src_20180705'&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;Could someone tell me why this happens and how to solve this problem?&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jul 2018 06:23:16 GMT</pubDate>
    <dc:creator>tac24</dc:creator>
    <dc:date>2018-07-12T06:23:16Z</dc:date>
    <item>
      <title>How can I give source string dynamically in COLLECT command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-give-source-string-dynamically-in-COLLECT-command/m-p/436078#M124310</link>
      <description>&lt;P&gt;I want to extract a value dynamically in a subsearch and give the value (string) to source= &amp;lt;&amp;lt; string&amp;gt;&amp;gt; of COLLECT command.  The following example is extracting YYYYMMDD from the source field and making "src_yyyymmdd" string that will be given to source=&amp;lt;&amp;lt; string&amp;gt;&amp;gt;  of the COLLECT command. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    main search... | collect index="ABC" source=[search index="XYZ" 
        |head 1 | rex field=source "^FILENAME_(?&amp;lt;YYYYMMDD&amp;gt;\d{8})_.*"
        | eval fieldval="\""+"src_"+YYYYMMDD+"\""  
        | table source YYYYMMDD fieldval
        | return $fieldval]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I checked the above subsearch as a main search, every field value after table command was what I expected.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5363i43EA31FA86914124/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Unfortunately, the result was  &lt;EM&gt;Error in 'collect' command: Invalid argument: 'src_20180705'&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;Could someone tell me why this happens and how to solve this problem?&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 06:23:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-give-source-string-dynamically-in-COLLECT-command/m-p/436078#M124310</guid>
      <dc:creator>tac24</dc:creator>
      <dc:date>2018-07-12T06:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: How can I give source string dynamically in COLLECT command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-give-source-string-dynamically-in-COLLECT-command/m-p/436079#M124311</link>
      <description>&lt;P&gt;Hello @tac24,&lt;/P&gt;

&lt;P&gt;the documentation states : Syntax: source= (from &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Collect"&gt;http://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Collect&lt;/A&gt;).&lt;/P&gt;

&lt;P&gt;It seems that you have the same problem as this one : &lt;A href="https://answers.splunk.com/answers/240798/how-to-return-a-single-value-from-a-subsearch-into.html"&gt;https://answers.splunk.com/answers/240798/how-to-return-a-single-value-from-a-subsearch-into.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;So, this should do :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;main search... | collect index="ABC" source=[search index="XYZ" 
         |head 1 | rex field=source "^FILENAME_(?&amp;lt;YYYYMMDD&amp;gt;\d{8})_.*"
         | eval val="src_".YYYYMMDD
         | eval fieldval="\"".val."\""
         | table source YYYYMMDD fieldval
         | return $fieldval]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Jul 2018 06:20:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-give-source-string-dynamically-in-COLLECT-command/m-p/436079#M124311</guid>
      <dc:creator>poete</dc:creator>
      <dc:date>2018-07-16T06:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: How can I give source string dynamically in COLLECT command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-give-source-string-dynamically-in-COLLECT-command/m-p/436080#M124312</link>
      <description>&lt;P&gt;@tac24 can you not override the source field even before the collect command with the value you need?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval source= [&amp;lt;yourQueryToGetNewSource&amp;gt;]
| collect &amp;lt;yourCommandArguments&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Jul 2018 06:37:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-give-source-string-dynamically-in-COLLECT-command/m-p/436080#M124312</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-07-16T06:37:59Z</dc:date>
    </item>
  </channel>
</rss>

