<?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: Default value for transform in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17472#M88588</link>
    <description>&lt;P&gt;$0 is used differently here. The documentation is correct as $0 is original value of DEST_KEY. I've already tested that.&lt;BR /&gt;
What I want is to add something to DEST_KEY (which already contains a value) if the regex matches and a default value if not. The problem is that the default value should be added to DEST_KEY and not overwrite it.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 09:15:13 GMT</pubDate>
    <dc:creator>wollinet</dc:creator>
    <dc:date>2020-09-28T09:15:13Z</dc:date>
    <item>
      <title>Default value for transform</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17470#M88586</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;FORMAT = &amp;lt;string&amp;gt;
* The special identifier $0 represents what was in the DEST_KEY before this regex was performed.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can I use $0 in DEFAULT_VALUE, too ? My intention is to add a default value to the current content of the source key, if the regex doesn't match.&lt;/P&gt;

&lt;P&gt;Any help appreciated.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Here's some more information about what I want to do. I need to build the index name from several fields in the record (e.g. stage and logtype). In some cases I can directly use the value from the record in some other cases not. I tried the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;props.conf:
TRANSFORMS-index_stage = index_stage_prod, index_stage_test, index_logtype
...

transforms.conf:

[index_stage_prod] 
DEST_KEY = _MetaData:Index 
REGEX = (?i)stage=(PROD|BCP).* 
FORMAT = "idx_prod"

[index_stage_test] 
DEST_KEY = _MetaData:Index 
REGEX = (?i)stage=(DEV|TEST).* 
FORMAT = "idx_test"

[index_logtype] 
DEST_KEY = _MetaData:Index 
REGEX = (?i)logtype=([^\s\t\r]*).* 
FORMAT = $0_$1 
DEFAULT_VALUE = $0_unclassified 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The seem to be at least two problems:
1) It seems that building the index name incrementally doesn't work. My tests showed that if the first transform was successful the other transforms do not fire. 
2) I need "$0" to work in DEFAULT_VALUE&lt;/P&gt;

&lt;P&gt;I workaround would be to match all values with one regular expression, but that has some limitations. I will also open a case about that problem.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jul 2010 23:29:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17470#M88586</guid>
      <dc:creator>wollinet</dc:creator>
      <dc:date>2010-07-15T23:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Default value for transform</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17471#M88587</link>
      <description>&lt;P&gt;I don't think this is possible.  In the common field extraction (fields loaded at search-time) it is not possible to augment the regex extracted values.  So it seems unlikely that you could augment the previous value of the &lt;CODE&gt;DEST_KEY&lt;/CODE&gt; (&lt;CODE&gt;$0&lt;/CODE&gt;) with some additional static text that would work when you don't have a match.  Certainly there would be ways of accomplishing this using an &lt;CODE&gt;eval&lt;/CODE&gt; statement, but I don't think you can do this simply with a transformer.&lt;/P&gt;

&lt;P&gt;Here is an example demonstrating what I mean about adding static text to a field.  This example will &lt;STRONG&gt;not&lt;/STRONG&gt; work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[my-bogus-transformer]
REGEX = \s(\d+)\s
FORMAT = my_field::"$1 (int)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This does not work, because the text " (int)" is NOT part of the raw text and you can't just arbitrarily add text to extracted fields like this.  (Unless you use do index-time field extractions, which I don't recommend here.)  My understanding is that this has to do with search performance and the fact that a search like &lt;CODE&gt;field1=joe&lt;/CODE&gt; is turned into the search &lt;CODE&gt;joe AND field1="joe"&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jul 2010 20:53:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17471#M88587</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-07-16T20:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Default value for transform</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17472#M88588</link>
      <description>&lt;P&gt;$0 is used differently here. The documentation is correct as $0 is original value of DEST_KEY. I've already tested that.&lt;BR /&gt;
What I want is to add something to DEST_KEY (which already contains a value) if the regex matches and a default value if not. The problem is that the default value should be added to DEST_KEY and not overwrite it.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 09:15:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17472#M88588</guid>
      <dc:creator>wollinet</dc:creator>
      <dc:date>2020-09-28T09:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Default value for transform</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17473#M88589</link>
      <description>&lt;P&gt;Wollinet, you are correct.  I've updated by answer and removed my incorrect understanding of how splunk is using &lt;CODE&gt;$0&lt;/CODE&gt; in this case vs the traditional regex meaning of &lt;CODE&gt;$0&lt;/CODE&gt;.  I think an &lt;CODE&gt;eval&lt;/CODE&gt; based approach is your best (and possibly only) option.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jul 2010 22:12:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17473#M88589</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-07-19T22:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: Default value for transform</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17474#M88590</link>
      <description>&lt;P&gt;"eval" doesn't help, since I need that functionality during indexing. I want to dynamically choose the index where the record is stored.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2010 20:27:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17474#M88590</guid>
      <dc:creator>wollinet</dc:creator>
      <dc:date>2010-07-20T20:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Default value for transform</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17475#M88591</link>
      <description>&lt;P&gt;Hmm, that's a very different scenario that I thought you were asking about. Index-time transforms don't have the limitation that I described above, but I'm not sure knowing that solves anything.... I think if you update your questions with a use-case example or two, there may be another possible solution.  It's also possible this should be a feature request, but either way you'll need to give more details about what your use-case is.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2010 20:56:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17475#M88591</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-07-20T20:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Default value for transform</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17476#M88592</link>
      <description>&lt;P&gt;After a lot of testing I'm now sure that $0 doesn't work in DEFAULT_VALUE. I'm gonna file an enhancement request.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2010 20:16:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Default-value-for-transform/m-p/17476#M88592</guid>
      <dc:creator>wollinet</dc:creator>
      <dc:date>2010-07-29T20:16:54Z</dc:date>
    </item>
  </channel>
</rss>

