<?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 How to autofill field name with field extraction or dynamic rex statement? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-autofill-field-name-with-field-extraction-or-dynamic-rex/m-p/179748#M51754</link>
    <description>&lt;P&gt;So I have the following data in the log file and would like to be able to search on the specific field name, but unfortunately the data is not in key=value or key:value it's in {"key","value"} format.&lt;/P&gt;

&lt;P&gt;Is there any way to do field extraction or a dynamic rex statement to auto-fill the fieldname slot?&lt;/P&gt;

&lt;P&gt;Example Data set #1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"type","voice"}
{"ani","4561585649"}
{"dnis","956165165"}
{"primary_ani","456159"}
{"primary_dnis","4565657"}
{"loginid","556467db000000000a5c343c45aac2"}
{"agent_key",""}
{"voice_direction","inbound"}
{"calltype","direct"}
{"ctype","direct"}
{"ucid","00002156156564451418"}
{"vdu_id","556467db000000000a5c343c45aac2"}
{"owner","556467db000000000a5c343c45aac2"}
{"createtime","2014-08-12 16:36:58"}
{"createtimet","1407961859"}
{"phone",""}
{"dest","5555555"}
{"orig","91584786594"}
{"ext","55555555"}
{"agent",""}
{"agent.1","556467db000000000a5c343c45aac2"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example Data set #2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"Comp.adjunct.+",""}
{"Comp.Abandon","N"}
{"Comp.ScreenPopType","None"}
{"Comp.adjunct..leg_id","6"}
{"Comp.adjunct..origvdn","5658978"}
{"Comp.adjunct..destvdn","1589586"}
{"Comp.adjunctcount","6"}
{"Comp.adjunct..report_name","NULL"}
{"Comp.CalltypeCategory","Cust_Service"}
{"Comp.Region","Midwest"}
{"Comp.destvdn","5698578"}
{"Comp.adjunct..dnis","1548659"}
{"Comp.adjunct..menuname"," "}
{"Comp.SurveyCode",""}
{"Comp.adjunct..workflow","dept.calltype_route"}
{"Comp.adjunct..calltype","english_ea_general"}
{"Comp.adjunct..staffinggroup","AAAA"}
{"Comp.adjunct..calltypecategory","Cust_Service"}
{"Comp.CallType","english_ea_general"}
{"Comp.StaffingGroup","AAAA"}
{"Comp.ANI","5847859356"}
{"uui","1589648795,,,5689475,1"}
{"Comp.language","EN"}
{"Comp.todcheck","GENERAL"}
{"Comp.adjunct..timestamp","2014-08-12 11:28:08.681"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since I cannot guarantee the order or that all the fields will be present the only way I can think of achieving this is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=text
| fields _raw
| rex field=_raw "\{\"type\",\"(?&amp;lt;type&amp;gt;.*?)\"\}"
| rex field=_raw "\{\"primary_ani\",\"(?&amp;lt;primary_ani&amp;gt;.*?)\"\}"
| rex field=_raw "\{\"dest\",\"(?&amp;lt;dest&amp;gt;.*?)\"\}"
| rex field=_raw "\{\"orig\",\"(?&amp;lt;orig&amp;gt;.*?)\"\}"
| where type="voice" AND dest!="" | table *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Aug 2014 21:55:40 GMT</pubDate>
    <dc:creator>steven10172</dc:creator>
    <dc:date>2014-08-12T21:55:40Z</dc:date>
    <item>
      <title>How to autofill field name with field extraction or dynamic rex statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-autofill-field-name-with-field-extraction-or-dynamic-rex/m-p/179748#M51754</link>
      <description>&lt;P&gt;So I have the following data in the log file and would like to be able to search on the specific field name, but unfortunately the data is not in key=value or key:value it's in {"key","value"} format.&lt;/P&gt;

&lt;P&gt;Is there any way to do field extraction or a dynamic rex statement to auto-fill the fieldname slot?&lt;/P&gt;

&lt;P&gt;Example Data set #1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"type","voice"}
{"ani","4561585649"}
{"dnis","956165165"}
{"primary_ani","456159"}
{"primary_dnis","4565657"}
{"loginid","556467db000000000a5c343c45aac2"}
{"agent_key",""}
{"voice_direction","inbound"}
{"calltype","direct"}
{"ctype","direct"}
{"ucid","00002156156564451418"}
{"vdu_id","556467db000000000a5c343c45aac2"}
{"owner","556467db000000000a5c343c45aac2"}
{"createtime","2014-08-12 16:36:58"}
{"createtimet","1407961859"}
{"phone",""}
{"dest","5555555"}
{"orig","91584786594"}
{"ext","55555555"}
{"agent",""}
{"agent.1","556467db000000000a5c343c45aac2"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example Data set #2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"Comp.adjunct.+",""}
{"Comp.Abandon","N"}
{"Comp.ScreenPopType","None"}
{"Comp.adjunct..leg_id","6"}
{"Comp.adjunct..origvdn","5658978"}
{"Comp.adjunct..destvdn","1589586"}
{"Comp.adjunctcount","6"}
{"Comp.adjunct..report_name","NULL"}
{"Comp.CalltypeCategory","Cust_Service"}
{"Comp.Region","Midwest"}
{"Comp.destvdn","5698578"}
{"Comp.adjunct..dnis","1548659"}
{"Comp.adjunct..menuname"," "}
{"Comp.SurveyCode",""}
{"Comp.adjunct..workflow","dept.calltype_route"}
{"Comp.adjunct..calltype","english_ea_general"}
{"Comp.adjunct..staffinggroup","AAAA"}
{"Comp.adjunct..calltypecategory","Cust_Service"}
{"Comp.CallType","english_ea_general"}
{"Comp.StaffingGroup","AAAA"}
{"Comp.ANI","5847859356"}
{"uui","1589648795,,,5689475,1"}
{"Comp.language","EN"}
{"Comp.todcheck","GENERAL"}
{"Comp.adjunct..timestamp","2014-08-12 11:28:08.681"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Since I cannot guarantee the order or that all the fields will be present the only way I can think of achieving this is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=text
| fields _raw
| rex field=_raw "\{\"type\",\"(?&amp;lt;type&amp;gt;.*?)\"\}"
| rex field=_raw "\{\"primary_ani\",\"(?&amp;lt;primary_ani&amp;gt;.*?)\"\}"
| rex field=_raw "\{\"dest\",\"(?&amp;lt;dest&amp;gt;.*?)\"\}"
| rex field=_raw "\{\"orig\",\"(?&amp;lt;orig&amp;gt;.*?)\"\}"
| where type="voice" AND dest!="" | table *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Aug 2014 21:55:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-autofill-field-name-with-field-extraction-or-dynamic-rex/m-p/179748#M51754</guid>
      <dc:creator>steven10172</dc:creator>
      <dc:date>2014-08-12T21:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to autofill field name with field extraction or dynamic rex statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-autofill-field-name-with-field-extraction-or-dynamic-rex/m-p/179749#M51755</link>
      <description>&lt;P&gt;Define a transforms.conf stanza like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[some_key_value_name]
REGEX = \{"(?&amp;lt;_KEY_1&amp;gt;[^"]+)","(?&amp;lt;_VAL_1&amp;gt;[^"]+)"\}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Apply that your your sourcetype in props.conf like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your_sourcetype]
...
REPORT-foo = some_key_value_name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Those two magic field names handle extraction of both the field name and field value in one go. See &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.3/Admin/transformsconf"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.3/Admin/transformsconf&lt;/A&gt; for reference.&lt;/P&gt;

&lt;P&gt;Note, my regex expects no escaped double quotes in either the field name or value. If that can happen then you need to be a bit more careful with the expression.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2014 23:00:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-autofill-field-name-with-field-extraction-or-dynamic-rex/m-p/179749#M51755</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-08-12T23:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to autofill field name with field extraction or dynamic rex statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-autofill-field-name-with-field-extraction-or-dynamic-rex/m-p/179750#M51756</link>
      <description>&lt;P&gt;You have one option which to create a transform for your sourcetype.   Below is a props and transfroms created from your sample data.  I've tested this against the sample and it works, milage may vary.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;BR /&gt;
#props.conf&lt;BR /&gt;
[foobarsourcetype]&lt;BR /&gt;
REPORTS-spam = spam&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;
&lt;CODE&gt;&lt;/CODE&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;BR /&gt;
#transforms.conf&lt;BR /&gt;
[spam]&lt;BR /&gt;
SOURCE_KEY = _raw&lt;BR /&gt;
REGEX  = {"([^"]+)","([^"]+)"}&lt;BR /&gt;
FORMAT = $1::$2&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;Hopes this helps.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2014 23:11:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-autofill-field-name-with-field-extraction-or-dynamic-rex/m-p/179750#M51756</guid>
      <dc:creator>bmacias84</dc:creator>
      <dc:date>2014-08-12T23:11:50Z</dc:date>
    </item>
  </channel>
</rss>

