<?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 field value pairs in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-would-I-extract-field-value-pairs-from-these-sample-events-2/m-p/610765#M212403</link>
    <description>&lt;P&gt;The problem is the key/value pairs are separated a major breaker (space).&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have control over the logging, removal of that space will result in automatic field extraction for the entire event, as : (colon) is a minor breaker.&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/SCS/current/Search/Eventsegmentationandsearching" target="_blank"&gt;https://docs.splunk.com/Documentation/SCS/current/Search/Eventsegmentationandsearching&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Using a regular expression as you described is the best option here, unless you can transform the data to remove the space, however that in itself will be an expensive regex operation. You may as well just extract at search time using regex like the one you provided.&lt;/P&gt;</description>
    <pubDate>Wed, 24 Aug 2022 23:58:34 GMT</pubDate>
    <dc:creator>chaker</dc:creator>
    <dc:date>2022-08-24T23:58:34Z</dc:date>
    <item>
      <title>How would I extract field/value pairs from these sample events (2 sample events given below)?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-would-I-extract-field-value-pairs-from-these-sample-events-2/m-p/610759#M212401</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;How would I extract field/value pairs from these sample events (2 sample events given below)?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can use like ......&lt;STRONG&gt;ID : (?P&amp;lt;ID&amp;gt;\w+)&lt;/STRONG&gt;........but are there any good ways to get these key/value pairs. Thank you so much, would appreciate your support.&lt;/P&gt;
&lt;P&gt;23:51:43.670 |LogMessage ID : sxntest ClientAddress : 10.207.68.172 Level : 6 EventType : UserLogging Resource: RESTIP EventStatus : Success CEvent : No Category : TestEvent ComID : VMREST CorrelationID : DetailsInfo : Login App ID: DSTest Cluster ID: Node ID: XP2SENTAtPCBUC1&lt;/P&gt;
&lt;P&gt;23:51:43.789 |LogMessage ID : sxntest ClientAddress : 10.207.68.175 Level : 7 EventType : UserLogging Resource: RESTIP EventStatus : Success CEvent : No Category : TestEvent ComID : VMREST CorrelationID : DetailsInfo : Login App ID: DSTest Cluster ID: 09XV4R Node ID: XP2SENTXRTPCBUC&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2022 00:25:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-would-I-extract-field-value-pairs-from-these-sample-events-2/m-p/610759#M212401</guid>
      <dc:creator>SplunkDash</dc:creator>
      <dc:date>2022-08-25T00:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field value pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-would-I-extract-field-value-pairs-from-these-sample-events-2/m-p/610765#M212403</link>
      <description>&lt;P&gt;The problem is the key/value pairs are separated a major breaker (space).&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have control over the logging, removal of that space will result in automatic field extraction for the entire event, as : (colon) is a minor breaker.&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/SCS/current/Search/Eventsegmentationandsearching" target="_blank"&gt;https://docs.splunk.com/Documentation/SCS/current/Search/Eventsegmentationandsearching&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Using a regular expression as you described is the best option here, unless you can transform the data to remove the space, however that in itself will be an expensive regex operation. You may as well just extract at search time using regex like the one you provided.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 23:58:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-would-I-extract-field-value-pairs-from-these-sample-events-2/m-p/610765#M212403</guid>
      <dc:creator>chaker</dc:creator>
      <dc:date>2022-08-24T23:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field value pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-would-I-extract-field-value-pairs-from-these-sample-events-2/m-p/610767#M212404</link>
      <description>&lt;P&gt;Tricky to determine what is the field and what is the value. It seems that value follows : character, but field names appear to have spaces in them (LogMessage ID, Cluster ID, Node ID).&amp;nbsp; It's not clear if the value for CorrelationID is 'DetailsInfo' or nothing, as the data becomes a bit unclear.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks like it's not possible to determine if the field has no value or not, e.g. see Cluster ID in the first row, which appears to have no value, compared with the second row, where it has a value.&lt;/P&gt;&lt;P&gt;Using the 'extract' command would normally allow you to get at these fields, but same issue applies in defining a consistent pattern. This SPL shows how one way to do this type of KV extraction, but it's a but clunky and does not work correctly because for Cluster ID in the first row it gets the word 'Node'.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval x=split("23:51:43.670 |LogMessage ID : sxntest ClientAddress : 10.207.68.172 Level : 6 EventType : UserLogging Resource: RESTIP EventStatus : Success CEvent : No Category : TestEvent ComID : VMREST CorrelationID : DetailsInfo : Login App ID: DSTest Cluster ID: Node ID: XP2SENTAtPCBUC1###23:51:43.789 |LogMessage ID : sxntest ClientAddress : 10.207.68.175 Level : 7 EventType : UserLogging Resource: RESTIP EventStatus : Success CEvent : No Category : TestEvent ComID : VMREST CorrelationID : DetailsInfo : Login App ID: DSTest Cluster ID: 09XV4R Node ID: XP2SENTXRTPCBUC", "###")
| mvexpand x
| rename x as _raw
| rex "\|(?&amp;lt;fields&amp;gt;.*)"
| fields - _raw
| rex max_match=0 field=fields "(?&amp;lt;key&amp;gt;[^:]*): (?&amp;lt;value&amp;gt;[^ ]*)"
| eval key=trim(key)
| foreach 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [ eval _k=mvindex(key, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;), _v=mvindex(value, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;), {_k}=_v ]
| fields - _raw _k _v fields key value&lt;/LI-CODE&gt;&lt;P&gt;If there is no general rule you can write regex for, then you're probably going to have to write a specific rex line to match field names + values as your example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2022 00:16:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-would-I-extract-field-value-pairs-from-these-sample-events-2/m-p/610767#M212404</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-08-25T00:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field value pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-would-I-extract-field-value-pairs-from-these-sample-events-2/m-p/610768#M212405</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Thank you so much. How could I use this in my props/transforms configuration files? Thank you again!&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2022 00:47:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-would-I-extract-field-value-pairs-from-these-sample-events-2/m-p/610768#M212405</guid>
      <dc:creator>SplunkDash</dc:creator>
      <dc:date>2022-08-25T00:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Extract field value pairs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-would-I-extract-field-value-pairs-from-these-sample-events-2/m-p/610769#M212406</link>
      <description>&lt;P&gt;I'm not always 100% sure of the props/transforms, but in transforms.conf, you'd need&lt;/P&gt;&lt;P&gt;REGEX = .... define the regex here to capture key=value&lt;/P&gt;&lt;P&gt;and then the&lt;/P&gt;&lt;PRE&gt;FORMAT = $1::$2&lt;/PRE&gt;&lt;P&gt;to make the key=value as fields, however, unless you can get the relevant regex to guarantee the parsing, you'll end up with possible field mismatches&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Admin/transformsconf" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/latest/Admin/transformsconf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here's a good description of setting it up&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/SplunkCloud/latest/Knowledge/Exampleconfigurationsusingfieldtransforms" target="_blank"&gt;https://docs.splunk.com/Documentation/SplunkCloud/latest/Knowledge/Exampleconfigurationsusingfieldtransforms&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2022 01:03:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-would-I-extract-field-value-pairs-from-these-sample-events-2/m-p/610769#M212406</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-08-25T01:03:02Z</dc:date>
    </item>
  </channel>
</rss>

