<?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 do a field extraction on userid? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-do-a-field-extraction-on-userid/m-p/456924#M129135</link>
    <description>&lt;P&gt;Hey Mbasharat,&lt;/P&gt;

&lt;P&gt;If you're just trying to extract the userId field, this should work for you:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...BASE SEARCH...
| rex field=_raw "\&amp;lt;userId\&amp;gt;(?&amp;lt;userId&amp;gt;[^\&amp;lt;]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, what may be more useful to you is looking into the &lt;CODE&gt;xmlkv&lt;/CODE&gt; command. Try it by adding this to your search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...BASE SEARCH...
|table _time _raw
| xmlkv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There is decent chunk of your data in XML format  (&amp;lt;field&amp;gt;value&amp;lt;/field&amp;gt;). This this command will automatically find and extract those fields. Since userId is in XML format, it too will automatically be extracted. &lt;/P&gt;

&lt;P&gt;Here is the documentation on the xmlkv command if you're interested on learning more about how it works:&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Xmlkv"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Xmlkv&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Jul 2019 19:36:35 GMT</pubDate>
    <dc:creator>rbechtold</dc:creator>
    <dc:date>2019-07-05T19:36:35Z</dc:date>
    <item>
      <title>How to do a field extraction on userid?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-do-a-field-extraction-on-userid/m-p/456922#M129133</link>
      <description>&lt;P&gt;I have an event as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2019-07-05 14:00:14 CDT d453bce1-aa68-4674-988e-ed6ab174a1d4 out: ID-sample.sample.com-1562306630255-1-1391 &lt;A href="https://sample.sample.com:8675/api/sample/platform/audits" target="test_blank"&gt;https://sample.sample.com:8675/api/sample/platform/audits&lt;/A&gt; {"messageId":"201","messageStatus":"Created","message":"Audit [appName=IDV, userType=TAXFILER, eventId=COLLECT, eventType=RESPONSES, fileSourceCd=IMF, ipAddr=00.00.00.00, returnCd=SUCCESS, sessionId=OLA_934d5c5f-974d-4b65-b0ca-288f03d5993e, vardata=&amp;lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?&amp;gt;&amp;lt;saasVarData&amp;gt;&amp;lt;body&amp;gt;{\"deviceId\":\"ABC5426\",\"ipAddress\":\"00.00.00.00\",\"answers\":[{\"questionNumber\":\"1\",\"answer\":\"Y\"},{\"questionNumber\":\"2\",\"answer\":\"Y\"},{\"questionNumber\":\"3\",\"answer\":\"N\"}]}&amp;lt;/body&amp;gt;&amp;lt;host&amp;gt;sample1.sample.net&amp;lt;/host&amp;gt;&amp;lt;ipAddress&amp;gt;00.00.00.00&amp;lt;/ipAddress&amp;gt;&amp;lt;requestId&amp;gt;d453bce1-aa68-4674-988e-ed6ab174a1d4&amp;lt;/requestId&amp;gt;&amp;lt;responseStatus&amp;gt;0&amp;lt;/responseStatus&amp;gt;&amp;lt;uri&amp;gt;/ola/id-verify/responses&amp;lt;/uri&amp;gt;&amp;lt;userId&amp;gt;C3C7EA8A-8B7A-4574-BCB9-FC326816E63B&amp;lt;/userId&amp;gt;&amp;lt;/saasVarData&amp;gt;]"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to do field extraction on userId. I used Splunk field extraction using RegEx method. After extraction, when I try to run searches against this field, it does not populate/provide counts correctly. It is picking only some field values and placing remaining ones under unknown. What am I missing? Thanks in advance.&lt;/P&gt;

&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Date>Fri, 05 Jul 2019 18:56:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-do-a-field-extraction-on-userid/m-p/456922#M129133</guid>
      <dc:creator>mbasharat</dc:creator>
      <dc:date>2019-07-05T18:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a field extraction on userid?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-do-a-field-extraction-on-userid/m-p/456923#M129134</link>
      <description>&lt;P&gt;Hey Mbasharat,&lt;/P&gt;

&lt;P&gt;do you need the entire log extracted, or just the userId field?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2019 19:19:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-do-a-field-extraction-on-userid/m-p/456923#M129134</guid>
      <dc:creator>rbechtold</dc:creator>
      <dc:date>2019-07-05T19:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a field extraction on userid?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-do-a-field-extraction-on-userid/m-p/456924#M129135</link>
      <description>&lt;P&gt;Hey Mbasharat,&lt;/P&gt;

&lt;P&gt;If you're just trying to extract the userId field, this should work for you:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...BASE SEARCH...
| rex field=_raw "\&amp;lt;userId\&amp;gt;(?&amp;lt;userId&amp;gt;[^\&amp;lt;]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, what may be more useful to you is looking into the &lt;CODE&gt;xmlkv&lt;/CODE&gt; command. Try it by adding this to your search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...BASE SEARCH...
|table _time _raw
| xmlkv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There is decent chunk of your data in XML format  (&amp;lt;field&amp;gt;value&amp;lt;/field&amp;gt;). This this command will automatically find and extract those fields. Since userId is in XML format, it too will automatically be extracted. &lt;/P&gt;

&lt;P&gt;Here is the documentation on the xmlkv command if you're interested on learning more about how it works:&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Xmlkv"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Xmlkv&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2019 19:36:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-do-a-field-extraction-on-userid/m-p/456924#M129135</guid>
      <dc:creator>rbechtold</dc:creator>
      <dc:date>2019-07-05T19:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to do a field extraction on userid?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-do-a-field-extraction-on-userid/m-p/456925#M129136</link>
      <description>&lt;P&gt;The last solution is what I liked! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; THANK YOU!!&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2019 21:24:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-do-a-field-extraction-on-userid/m-p/456925#M129136</guid>
      <dc:creator>mbasharat</dc:creator>
      <dc:date>2019-07-05T21:24:59Z</dc:date>
    </item>
  </channel>
</rss>

