<?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: How to remove path from spath field names in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222135#M65304</link>
    <description>&lt;P&gt;I actually am not going to know the exact path.  I updated the question.  &lt;/P&gt;

&lt;P&gt;The idea could work if it was &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rename "*.MessageID" AS MessageID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But Splunk doesn't seem to like wildcards in this command.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Nov 2015 06:13:45 GMT</pubDate>
    <dc:creator>j8lp</dc:creator>
    <dc:date>2015-11-09T06:13:45Z</dc:date>
    <item>
      <title>How to remove path from spath field names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222133#M65302</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;So I love the spath command.  With just one call, it will automatically extract and make searchable each and every field from each JSON log entries.  &lt;/P&gt;

&lt;P&gt;The only problem is that the spath command names each discovered field with that field's full path.  This is a problem when trying to match fields across logs with different structures.  For example, calling spth on the two log entries below will produce two different fields called "Request.Header.MessageID" and "Response.Header.MessageID" &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"Request":  {"Header":  {"MessageID":1234}}}
{"Response":  {"Header":  {"MessageID":1234}}}'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I actually am not going to know the exact message path or structure ahead of time.   It could be Request.Header.MessageID, Request.MessageID, or even Request.Body.MessageID . &lt;/P&gt;

&lt;P&gt;I'm looking for something that will just recognize that all of the fields that end with "MessageID" are referring to the same thing.&lt;/P&gt;

&lt;P&gt;Is there a way I can do that?  Does anyone know how I can remove the full path from the spath field names?  &lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 01:24:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222133#M65302</guid>
      <dc:creator>j8lp</dc:creator>
      <dc:date>2015-11-09T01:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove path from spath field names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222134#M65303</link>
      <description>&lt;P&gt;Hi j8lp,&lt;/P&gt;

&lt;P&gt;you can use &lt;CODE&gt;eval&lt;/CODE&gt; and &lt;CODE&gt;coalesce&lt;/CODE&gt; in your search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search here | spath | eval MessageID=coalesce("Request.Header.MessageID", "Request.MessageID", "Request.Body.MessageID"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will use either of the three possible &lt;CODE&gt;MessageID&lt;/CODE&gt; fields.&lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 02:43:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222134#M65303</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-11-09T02:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove path from spath field names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222135#M65304</link>
      <description>&lt;P&gt;I actually am not going to know the exact path.  I updated the question.  &lt;/P&gt;

&lt;P&gt;The idea could work if it was &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rename "*.MessageID" AS MessageID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But Splunk doesn't seem to like wildcards in this command.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 06:13:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222135#M65304</guid>
      <dc:creator>j8lp</dc:creator>
      <dc:date>2015-11-09T06:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove path from spath field names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222136#M65305</link>
      <description>&lt;P&gt;Updated the answer as well &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 07:46:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222136#M65305</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-11-09T07:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove path from spath field names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222137#M65306</link>
      <description>&lt;P&gt;Sorry if my question isn't clear, but I'm actually not going to know all the possible paths.  Is there a way to get coalesce everything that ends with ".MessageID" into a single field?  &lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 15:42:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222137#M65306</guid>
      <dc:creator>j8lp</dc:creator>
      <dc:date>2015-11-10T15:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove path from spath field names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222138#M65307</link>
      <description>&lt;P&gt;Okay, in this case I'm not sure if you would need &lt;CODE&gt;spath&lt;/CODE&gt; at all or if you're better off using a &lt;CODE&gt;rex&lt;/CODE&gt; :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your base search here | rex max_match=0 "[Mm]essage[IiDd]+":(?&amp;lt;MessageID&amp;gt;[^}]+)" | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;tested on regex101.con and with &lt;CODE&gt;pcregextest&lt;/CODE&gt; in Splunk with this examples:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"Request":  {"Header":  {"MessageID":1234}}}
{"Response":  {"Header":  {"MessageID":1234}}}'
{"Response":  {"Header":  {"messageID":1234}}}'
{"Response":  {"Header":  {"messageiD":1234}}}'
{"Response":  {"Header":  {"MessageId":1234}}}'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Just in case &lt;CODE&gt;MessageID&lt;/CODE&gt; could also contain lower case m, i and d &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 19:25:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/222138#M65307</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-11-10T19:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove path from spath field names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/569820#M198602</link>
      <description>&lt;P&gt;This would work if you did it without the quotes&lt;/P&gt;&lt;P&gt;e.g. | rename *.MessageID as MessageID&lt;/P&gt;&lt;P&gt;Another beneficial use of this function would also work in the opposite direction where you want to remove all prefixes from all fields:&lt;/P&gt;&lt;P&gt;| rename Request.Header.* as *&amp;nbsp;&lt;BR /&gt;| rename Response.Header.* as *&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 02:42:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-remove-path-from-spath-field-names/m-p/569820#M198602</guid>
      <dc:creator>bimord</dc:creator>
      <dc:date>2021-10-06T02:42:27Z</dc:date>
    </item>
  </channel>
</rss>

