<?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 Run the equivalent of an `extract` command on a structured JSON event's subfield in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470927#M80940</link>
    <description>&lt;P&gt;We're ingesting structured JSON logs from a source and would like to run the equivalent of the &lt;CODE&gt;extract&lt;/CODE&gt; command on one of the event's sub fields.  The events look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "field1":"value1",
    "field2":"value2",
    "field3":"value3",
    "msg":"field4=value4 field5=value5 field6=value6"
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The top level field1/field2/field3/msg fields are all being extracted as expected.  However, we'd also like to extract arbitrary key/value pairs defined in the &lt;CODE&gt;msg&lt;/CODE&gt; field, ideally at index time so that they're available to all searches.  The key/value pairs that exist in the &lt;CODE&gt;msg&lt;/CODE&gt; field are not known beforehand.  Is it possible to still extract them at index time and make them available to searches?&lt;/P&gt;

&lt;P&gt;We've been able to achieve the desired result with a search command chain like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...base search...
| rename _raw AS _temp 
| rename msg AS _raw 
| extract pairdelim="?&amp;amp;" kvdelim="=" 
| rename _raw AS msg 
| rename _temp AS _raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, we have some dashboards that run lots of searches, and we don't want to hack the above command chain into every individual search query.&lt;/P&gt;</description>
    <pubDate>Tue, 03 Sep 2019 18:57:50 GMT</pubDate>
    <dc:creator>ckarcher</dc:creator>
    <dc:date>2019-09-03T18:57:50Z</dc:date>
    <item>
      <title>Run the equivalent of an `extract` command on a structured JSON event's subfield</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470927#M80940</link>
      <description>&lt;P&gt;We're ingesting structured JSON logs from a source and would like to run the equivalent of the &lt;CODE&gt;extract&lt;/CODE&gt; command on one of the event's sub fields.  The events look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "field1":"value1",
    "field2":"value2",
    "field3":"value3",
    "msg":"field4=value4 field5=value5 field6=value6"
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The top level field1/field2/field3/msg fields are all being extracted as expected.  However, we'd also like to extract arbitrary key/value pairs defined in the &lt;CODE&gt;msg&lt;/CODE&gt; field, ideally at index time so that they're available to all searches.  The key/value pairs that exist in the &lt;CODE&gt;msg&lt;/CODE&gt; field are not known beforehand.  Is it possible to still extract them at index time and make them available to searches?&lt;/P&gt;

&lt;P&gt;We've been able to achieve the desired result with a search command chain like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...base search...
| rename _raw AS _temp 
| rename msg AS _raw 
| extract pairdelim="?&amp;amp;" kvdelim="=" 
| rename _raw AS msg 
| rename _temp AS _raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, we have some dashboards that run lots of searches, and we don't want to hack the above command chain into every individual search query.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 18:57:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470927#M80940</guid>
      <dc:creator>ckarcher</dc:creator>
      <dc:date>2019-09-03T18:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: Run the equivalent of an `extract` command on a structured JSON event's subfield</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470928#M80941</link>
      <description>&lt;P&gt;Hello @ckarcher,&lt;BR /&gt;
In case the format of msg does not change, you can use rex, as below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"field1\":\"value1\",\"field2\":\"value2\",\"field3\":\"value3\",\"msg\":\"field4=value4 field5=value5 field6=value6\"}"
| spath
| rex field=msg "field4=(?&amp;lt;field4&amp;gt;.*) field5=(?&amp;lt;field5&amp;gt;.*) field6=(?&amp;lt;field6&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Sep 2019 12:08:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470928#M80941</guid>
      <dc:creator>poete</dc:creator>
      <dc:date>2019-09-04T12:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: Run the equivalent of an `extract` command on a structured JSON event's subfield</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470929#M80942</link>
      <description>&lt;P&gt;@ckarcher,&lt;/P&gt;

&lt;P&gt;You can try this also:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval _raw="{\"field1\":\"value1\",\"field2\":\"value2\",\"field3\":\"value3\",\"msg\":\"field4=value4 field5=value5 field6=value6\"}" | extract | eval _raw=msg | extract
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Sep 2019 12:30:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470929#M80942</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-09-04T12:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: Run the equivalent of an `extract` command on a structured JSON event's subfield</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470930#M80943</link>
      <description>&lt;P&gt;Hi @poete - the format of the &lt;CODE&gt;msg&lt;/CODE&gt; field is unknown beforehand.  It may contain any number of arbitrary key/value pairs, and we want to extract them all.  I've updated the question to reflect this.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 14:13:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470930#M80943</guid>
      <dc:creator>ckarcher</dc:creator>
      <dc:date>2019-09-04T14:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Run the equivalent of an `extract` command on a structured JSON event's subfield</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470931#M80944</link>
      <description>&lt;P&gt;Hi @kamlesh_vaghela - we've already proven that it's possible to extract the K/V pairs from &lt;CODE&gt;msg&lt;/CODE&gt; at search time with an &lt;CODE&gt;extract&lt;/CODE&gt; command like you've provided.  However, we have dashboards with lots of searches in them, and we want to avoid hacking the &lt;CODE&gt;rename + extract&lt;/CODE&gt; command into each of them.  Do you know if it's possible to do this in a way that works for all searches against a given source type?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 14:15:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470931#M80944</guid>
      <dc:creator>ckarcher</dc:creator>
      <dc:date>2019-09-04T14:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: Run the equivalent of an `extract` command on a structured JSON event's subfield</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470932#M80945</link>
      <description>&lt;P&gt;@ckarcher,&lt;/P&gt;

&lt;P&gt;Can you please try by adding below configurations in &lt;CODE&gt;props.conf&lt;/CODE&gt;? &lt;/P&gt;

&lt;P&gt;File path: &lt;CODE&gt;SPLUNK_HOME/etc/apps/YOUR_APP/local/props.conf&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[YOUR_SOURCETYPE]
EXTRACT-field4,field5,field6 = ^[^=\n]*=(?P&amp;lt;field4&amp;gt;\w+)[^=\n]*=(?P&amp;lt;field5&amp;gt;\w+)[^=\n]*=(?P&amp;lt;field6&amp;gt;\w+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note: You may need to update the regular expression as per your events/requirement.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 08:49:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470932#M80945</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-09-05T08:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: Run the equivalent of an `extract` command on a structured JSON event's subfield</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470933#M80946</link>
      <description>&lt;P&gt;@ckarcher, &lt;/P&gt;

&lt;P&gt;please check my below answer.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 08:49:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470933#M80946</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-09-05T08:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: Run the equivalent of an `extract` command on a structured JSON event's subfield</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470934#M80947</link>
      <description>&lt;P&gt;Per the original post, the names of the key/value pairs in the &lt;CODE&gt;msg&lt;/CODE&gt; field are arbitrary and unknown beforehand.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 13:38:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470934#M80947</guid>
      <dc:creator>ckarcher</dc:creator>
      <dc:date>2019-09-05T13:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Run the equivalent of an `extract` command on a structured JSON event's subfield</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470935#M80948</link>
      <description>&lt;P&gt;I was able to solve this by creating two field transforms like the following that handle the case where the values are in quotes (e.g., &lt;CODE&gt;key1="value1 with spaces"&lt;/CODE&gt;) as well as the case where they aren't (e.g., &lt;CODE&gt;key1=value1withoutspaces&lt;/CODE&gt;).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;json_msg_transform_with_quotes
(?P&amp;lt;_KEY_1&amp;gt;\w+)="(?P&amp;lt;_VAL_1&amp;gt;[^"]*)"

json_msg_transform_without_quotes
(?P&amp;lt;_KEY_1&amp;gt;\w+)=(?P&amp;lt;_VAL_1&amp;gt;[^"\s]+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I then wired up two new field extractions that use those transforms on the desired source type, and I'm now seeing all the fields (both those from the raw JSON event as well as those embedded in the &lt;CODE&gt;msg&lt;/CODE&gt; field) available at query time.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 13:43:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Run-the-equivalent-of-an-extract-command-on-a-structured-JSON/m-p/470935#M80948</guid>
      <dc:creator>ckarcher</dc:creator>
      <dc:date>2019-09-05T13:43:20Z</dc:date>
    </item>
  </channel>
</rss>

