<?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 Routing to an dynamic index based on JSON field in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Routing-to-an-dynamic-index-based-on-JSON-field/m-p/417568#M73692</link>
    <description>&lt;P&gt;I have JSON data that I am ingesting.  I would like to route the event to an index based on one of the JSON fields.  I've seen examples that use REGEX, but I want to avoid hard coding the indexes since I will need to update multiple config files if I start getting new types of data.&lt;/P&gt;

&lt;P&gt;My JSON data includes the following section:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
"collection": {
  "date": "...",
  "source": &amp;lt;Canada | US | Mexico&amp;gt;
},
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to have 3 seperate indexes, one for Canada, US, and Mexico.  I would like to have the index determine dynamically based on the input. &lt;/P&gt;

&lt;P&gt;I've seen examples that suggest this is easy to do with REGEX, and I think I could do this as follows that way:&lt;/P&gt;

&lt;P&gt;indexes.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[index-Canada]
...
[index-US]
...
[index-Mexico]
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;props.conf:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[default]
TRUNCATE = 0
INDEX_EXTRACTIONS = json
TIMESTAMP_FIELDS = collection.date
TRANSFORMS-SetIndex = setIndex-Canada, setIndex-US, setIndex-Mexico
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms.conf:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[setIndex-Canada]
REGEX = "source": "Canada"
DEST_KEY = _MetaData::Index
FORMAT = index-Canada

[setIndex-US]
REGEX = "source": "US"
DEST_KEY = _MetaData::Index
FORMAT = index-US

[setIndex-Mexico]
REGEX = "source": "Mexico"
DEST_KEY = _MetaData::Index
FORMAT = index-Mexico
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I think this will work.  However, I would like to make it so that I don't have to hard code the transforms.conf for each index.  One way is to do the following:&lt;/P&gt;

&lt;P&gt;props.conf:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[default]
TRUNCATE = 0
INDEX_EXTRACTIONS = json
TIMESTAMP_FIELDS = collection.date
TRANSFORMS-SetIndex = setIndex
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[setIndex]
REGEX = "source": "(.*)"
DEST_KEY = _MetaData::Index
FORMAT = index-$1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have a couple questions about this:  &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;If the data has an index I haven't configured, can I somehow setup a fallback so that events that don't match a configured index are not lost?&lt;/LI&gt;
&lt;LI&gt; Can I use the SOURCE_KEY somehow to use the value of the JSON field instead of REGEX?  I would rather use the JSON parsing ability of Splunk than my REGEX skills to make sure I am getting the right field.  If somehow my REGEX shows up in the contents of the event later, I could get data routed to the wrong index. &lt;/LI&gt;
&lt;/OL&gt;</description>
    <pubDate>Mon, 10 Jun 2019 18:41:30 GMT</pubDate>
    <dc:creator>trenin</dc:creator>
    <dc:date>2019-06-10T18:41:30Z</dc:date>
    <item>
      <title>Routing to an dynamic index based on JSON field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Routing-to-an-dynamic-index-based-on-JSON-field/m-p/417568#M73692</link>
      <description>&lt;P&gt;I have JSON data that I am ingesting.  I would like to route the event to an index based on one of the JSON fields.  I've seen examples that use REGEX, but I want to avoid hard coding the indexes since I will need to update multiple config files if I start getting new types of data.&lt;/P&gt;

&lt;P&gt;My JSON data includes the following section:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
"collection": {
  "date": "...",
  "source": &amp;lt;Canada | US | Mexico&amp;gt;
},
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to have 3 seperate indexes, one for Canada, US, and Mexico.  I would like to have the index determine dynamically based on the input. &lt;/P&gt;

&lt;P&gt;I've seen examples that suggest this is easy to do with REGEX, and I think I could do this as follows that way:&lt;/P&gt;

&lt;P&gt;indexes.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[index-Canada]
...
[index-US]
...
[index-Mexico]
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;props.conf:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[default]
TRUNCATE = 0
INDEX_EXTRACTIONS = json
TIMESTAMP_FIELDS = collection.date
TRANSFORMS-SetIndex = setIndex-Canada, setIndex-US, setIndex-Mexico
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms.conf:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[setIndex-Canada]
REGEX = "source": "Canada"
DEST_KEY = _MetaData::Index
FORMAT = index-Canada

[setIndex-US]
REGEX = "source": "US"
DEST_KEY = _MetaData::Index
FORMAT = index-US

[setIndex-Mexico]
REGEX = "source": "Mexico"
DEST_KEY = _MetaData::Index
FORMAT = index-Mexico
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I think this will work.  However, I would like to make it so that I don't have to hard code the transforms.conf for each index.  One way is to do the following:&lt;/P&gt;

&lt;P&gt;props.conf:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[default]
TRUNCATE = 0
INDEX_EXTRACTIONS = json
TIMESTAMP_FIELDS = collection.date
TRANSFORMS-SetIndex = setIndex
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[setIndex]
REGEX = "source": "(.*)"
DEST_KEY = _MetaData::Index
FORMAT = index-$1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have a couple questions about this:  &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;If the data has an index I haven't configured, can I somehow setup a fallback so that events that don't match a configured index are not lost?&lt;/LI&gt;
&lt;LI&gt; Can I use the SOURCE_KEY somehow to use the value of the JSON field instead of REGEX?  I would rather use the JSON parsing ability of Splunk than my REGEX skills to make sure I am getting the right field.  If somehow my REGEX shows up in the contents of the event later, I could get data routed to the wrong index. &lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 10 Jun 2019 18:41:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Routing-to-an-dynamic-index-based-on-JSON-field/m-p/417568#M73692</guid>
      <dc:creator>trenin</dc:creator>
      <dc:date>2019-06-10T18:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: Routing to an dynamic index based on JSON field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Routing-to-an-dynamic-index-based-on-JSON-field/m-p/417569#M73693</link>
      <description>&lt;P&gt;For #1&lt;BR /&gt;
I think you'd need to handle that with some logical set of rules. May be something like defining 2 stanzas in transforms for setting your indexes. One would assign the index only if the sources are US, Mexico OR Canada :&lt;/P&gt;

&lt;P&gt;[setIndex_KnownLocations]&lt;BR /&gt;
 REGEX = "source": "&lt;A href="https://community.splunk.com/.*" target="_blank"&gt;Canada|US|Mexico&lt;/A&gt;"&lt;BR /&gt;
 DEST_KEY = _MetaData::Index&lt;BR /&gt;
 FORMAT = index-$1&lt;/P&gt;

&lt;P&gt;And the second would assign your backup index for all events from other sources :&lt;BR /&gt;
[setIndex_UnKnownLocations]&lt;BR /&gt;
 REGEX = "source": "(.*)"&lt;BR /&gt;
 DEST_KEY = _MetaData::Index&lt;BR /&gt;
 FORMAT = index-BackupIndex&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:52:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Routing-to-an-dynamic-index-based-on-JSON-field/m-p/417569#M73693</guid>
      <dc:creator>amitm05</dc:creator>
      <dc:date>2020-09-30T00:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: Routing to an dynamic index based on JSON field</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Routing-to-an-dynamic-index-based-on-JSON-field/m-p/417570#M73694</link>
      <description>&lt;P&gt;Thanks - I will try that.  Any thoughts for how to use the Splunk JSON parsing in favour of REGEX?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2019 19:17:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Routing-to-an-dynamic-index-based-on-JSON-field/m-p/417570#M73694</guid>
      <dc:creator>trenin</dc:creator>
      <dc:date>2019-06-14T19:17:34Z</dc:date>
    </item>
  </channel>
</rss>

