<?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: Extract multiple fields without knowing their order in TRANSFORMS in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-fields-without-knowing-their-order-in/m-p/475060#M133549</link>
    <description>&lt;P&gt;@to4kawa , it is a valid JSON, but KV_MODE is used for search-time field extractions only.&lt;BR /&gt;
In my case I need to use the JSON fields during indexing to actually decide which index will be used to store the events (but not save them as indexed fields)&lt;/P&gt;</description>
    <pubDate>Sun, 12 Apr 2020 20:48:27 GMT</pubDate>
    <dc:creator>ilya_resh</dc:creator>
    <dc:date>2020-04-12T20:48:27Z</dc:date>
    <item>
      <title>Extract multiple fields without knowing their order in TRANSFORMS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-fields-without-knowing-their-order-in/m-p/475058#M133547</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I need to extract multiple fields (from events that are coming via HEC) and assign an index based on the concatenated values.&lt;BR /&gt;
(I know that you can assign index per HEC token, but let's assume that all the events are coming with the same token)&lt;BR /&gt;
Example payload&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "sourcetype": "hec:generic",
    "event": {
        "platform": "platform01",
        "service": "service02",
        "env": "npd",
        "type": "alert",
        "test": "true",
        "message": "TEST HEC 040"
    }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;i've figured out how to do it if I know the order&lt;BR /&gt;
props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[hec:generic]
TRANSFORMS-index_selector = index_selector
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[index_selector]
REGEX =  platform"\s?:\s?"(?P&amp;lt;platform&amp;gt;\w+)",\n\s*"service"\s?:\s?"(?P&amp;lt;service&amp;gt;\w+)",\n\s*"env"\s?:\s?"(?P&amp;lt;env&amp;gt;\w+)
DEST_KEY = _MetaData:Index
FORMAT   = $1_$2_$3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But what if I don't know the order of the platform , service and env fields?&lt;BR /&gt;
Any suggestions?&lt;BR /&gt;
Can I somehow have 3 separate REGEX lines?&lt;BR /&gt;
Tried below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    REGEX =  platform"\s?:\s?"(?P&amp;lt;platform&amp;gt;\w+)
    REGEX =  service"\s?:\s?"(?P&amp;lt;service&amp;gt;\w+)
    REGEX =  env"\s?:\s?"(?P&amp;lt;env&amp;gt;\w+)
    DEST_KEY = _MetaData:Index
    FORMAT   = $1_$2_$3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and the result it just picks up the last REGEX, so basically it tries to assign "npd_$2_$3" to index&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:59:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-fields-without-knowing-their-order-in/m-p/475058#M133547</guid>
      <dc:creator>ilya_resh</dc:creator>
      <dc:date>2020-09-30T04:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Extract multiple fields without knowing their order in TRANSFORMS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-fields-without-knowing-their-order-in/m-p/475059#M133548</link>
      <description>&lt;P&gt;you JSON is valid&lt;/P&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[hec:generic]
TRANCATE = 0
DATETIME_CONFIG = CURRENT
SEDCMD-remove = s/^.*?fields\":\s({.*?}).*/\1/
INDEXED_EXTRACTIONS = json
KV_MODE = none
TRANSFORMS-index_selector = index_selector
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Splunk default: &lt;CODE&gt;KV_MODE = auto&lt;/CODE&gt;&lt;BR /&gt;
json is extracted appropriate.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 22:12:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-fields-without-knowing-their-order-in/m-p/475059#M133548</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-04-10T22:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: Extract multiple fields without knowing their order in TRANSFORMS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-fields-without-knowing-their-order-in/m-p/475060#M133549</link>
      <description>&lt;P&gt;@to4kawa , it is a valid JSON, but KV_MODE is used for search-time field extractions only.&lt;BR /&gt;
In my case I need to use the JSON fields during indexing to actually decide which index will be used to store the events (but not save them as indexed fields)&lt;/P&gt;</description>
      <pubDate>Sun, 12 Apr 2020 20:48:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-fields-without-knowing-their-order-in/m-p/475060#M133549</guid>
      <dc:creator>ilya_resh</dc:creator>
      <dc:date>2020-04-12T20:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extract multiple fields without knowing their order in TRANSFORMS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-fields-without-knowing-their-order-in/m-p/475061#M133550</link>
      <description>&lt;P&gt;try&lt;/P&gt;

&lt;P&gt;INDEXED_EXTRACTIONS = json&lt;BR /&gt;
    KV_MODE = none&lt;BR /&gt;
on props.conf&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:56:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-fields-without-knowing-their-order-in/m-p/475061#M133550</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-09-30T04:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Extract multiple fields without knowing their order in TRANSFORMS</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-fields-without-knowing-their-order-in/m-p/475062#M133551</link>
      <description>&lt;P&gt;I didn't want to have all the JSON fields been indexed.&lt;BR /&gt;
Here is what I came up with (still will need to asses performance impact)&lt;BR /&gt;
When sending HEC add fields portion&lt;BR /&gt;
So now the payload looks like that&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "sourcetype": "hec:generic",
    "fields": {
        "platform": "platform01",
        "service": "service02",
        "env": "npd"
    },
    "event": {
        "type": "alert",
        "test": "true",
        "message": "TEST HEC 046"
    }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[hec:generic]
TRANSFORMS-index_selector = index_selector
TRANSFORMS-remove_hec_meta = meta_remover
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[index_selector]
INGEST_EVAL = index=platform . "_" . service . "_" . env

[meta_remover]
INGEST_EVAL = env:=null(),  service:=null(),  platform:=null()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The meta_remover is optional in case one doesn't want to index fields that were used on selecting the index&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 21:39:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-fields-without-knowing-their-order-in/m-p/475062#M133551</guid>
      <dc:creator>ilya_resh</dc:creator>
      <dc:date>2020-04-14T21:39:46Z</dc:date>
    </item>
  </channel>
</rss>

