<?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 map a multivalued JSON Field Value(X) to its respective Field(Y) while writing datamodel Searches? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-to-map-a-multivalued-JSON-Field-Value-X-to-its-respective/m-p/375288#M6162</link>
    <description>&lt;P&gt;I am sure that I do not understand the full context here but very generally you need &lt;CODE&gt;mvzip&lt;/CODE&gt;, &lt;CODE&gt;mvindex&lt;/CODE&gt;, and possibly &lt;CODE&gt;mvfilter&lt;/CODE&gt; and &lt;CODE&gt;mvjoin&lt;/CODE&gt;..&lt;/P&gt;</description>
    <pubDate>Fri, 25 Aug 2017 15:55:32 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2017-08-25T15:55:32Z</dc:date>
    <item>
      <title>How to map a multivalued JSON Field Value(X) to its respective Field(Y) while writing datamodel Searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-map-a-multivalued-JSON-Field-Value-X-to-its-respective/m-p/375287#M6161</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I Have a Sample Event as Follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;     A: [
        {   [-]
         a1: xxx
         b1:xxxx    
        }   
        {   [-]
              a1: yyy
              b1:yyyy
        }   
    ]   
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Am Mapping the fields in Datamodel and Getting Values a1:xxx,yyy&lt;BR /&gt;
b1:xxxx,yyyy in the field.&lt;BR /&gt;
When The Query is written For a table What should be done to map the value xxx of a1 to xxxx of b1 and yyy of a1 to yyyy of b1 respectively from a datamodel.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 15:20:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-map-a-multivalued-JSON-Field-Value-X-to-its-respective/m-p/375287#M6161</guid>
      <dc:creator>bhargavnariyani</dc:creator>
      <dc:date>2017-08-23T15:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to map a multivalued JSON Field Value(X) to its respective Field(Y) while writing datamodel Searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-map-a-multivalued-JSON-Field-Value-X-to-its-respective/m-p/375288#M6162</link>
      <description>&lt;P&gt;I am sure that I do not understand the full context here but very generally you need &lt;CODE&gt;mvzip&lt;/CODE&gt;, &lt;CODE&gt;mvindex&lt;/CODE&gt;, and possibly &lt;CODE&gt;mvfilter&lt;/CODE&gt; and &lt;CODE&gt;mvjoin&lt;/CODE&gt;..&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 15:55:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-map-a-multivalued-JSON-Field-Value-X-to-its-respective/m-p/375288#M6162</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-25T15:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to map a multivalued JSON Field Value(X) to its respective Field(Y) while writing datamodel Searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-map-a-multivalued-JSON-Field-Value-X-to-its-respective/m-p/375289#M6163</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;A:
    [
    {    [-]
            a1: xxx
            b1:xxxx    
         }    
         {    [-]
               a1: yyy
               b1:yyyy
         }    
       ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As I understand your question, you need below result from above event using DataModel.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;a1    b1
--------------
xxx    xxxx
yyy    yyyy
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to share my views with Data model and Non- Data model approach.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;With DataModel Approach&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;With DataModel approach, we have to use tstats search and for the getting a1 and b1 columns we can write search like below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats values(datamodelName.node.a1) as a1,values(datamodelName.node.b1) as b1 
from datamodel=datamodelName 
where nodename=datamodelName.node 
by _time,YOUR_UNIQUE_ID_IF_ANY
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But this will also return multivalued in a1 and b1, with loosing mapping.&lt;/P&gt;

&lt;P&gt;I have tried to store node "A" (full JSON string ) in data model by using spath configuration in props.conf and tried with below search and I got expected result.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count
from datamodel=datamodelName 
where nodename=datamodelName.node 
by _time,YOUR_UNIQUE_ID_IF_ANY,datamodelName.node.A
| eval _raw=datamodelName.node.A 
| extract pairdelim="\"{,}" kvdelim=":" 
| table a1 b1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But it is very difficult and complex approach and I'm NOT SUGGESTING. Because DataModel is not for storing JSON object.&lt;BR /&gt;
It is good to keep data model as simple as possible.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Non-Data model Approach&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I'm suggesting Non-Data model Approach:&lt;/P&gt;

&lt;P&gt;The Non-data model approach, we have to write a plain search and extract multiple rows and columns from a single event by using mvzip, mvindex and split. &lt;/P&gt;

&lt;P&gt;See below search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;YOUR SEARCH 
| eval tempField=mvzip(a1,b1) 
| stats count by _time,YOUR_UNIQUE_ID_IF_ANY,tempField 
| eval a1=mvindex(split(tempField,","),0), b1=mvindex(split(tempField,","),1) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As per the JSON, node "A" contains multiple JSON objects this search will extract column a1 and b1. You can add more columns by using mvzip, splits &lt;/P&gt;

&lt;P&gt;Well, now we are replacing Data model to plain search so performance issue can be raised. So I suggest to put this search in savedsearch.conf and accelerate it. It will give you expected output and performance both.&lt;/P&gt;

&lt;P&gt;I hope this will help you.&lt;/P&gt;

&lt;P&gt;Thanks&lt;BR /&gt;
Kamlesh&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 07:41:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-map-a-multivalued-JSON-Field-Value-X-to-its-respective/m-p/375289#M6163</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-10-03T07:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to map a multivalued JSON Field Value(X) to its respective Field(Y) while writing datamodel Searches?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-map-a-multivalued-JSON-Field-Value-X-to-its-respective/m-p/375290#M6164</link>
      <description>&lt;P&gt;Used the Non DataModel Approach, It Worked Well...&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 09:36:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-map-a-multivalued-JSON-Field-Value-X-to-its-respective/m-p/375290#M6164</guid>
      <dc:creator>bhargavnariyani</dc:creator>
      <dc:date>2017-10-03T09:36:40Z</dc:date>
    </item>
  </channel>
</rss>

