<?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: Using MVZip and MVExpand on MultiValue fields where array sometimes doesnt exists in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-MVZip-and-MVExpand-on-MultiValue-fields-where-array/m-p/414675#M171876</link>
    <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | spath | table payload* timestamp | rename payload.recommendations{}.* as * payload.* as *  | fields - description modelName respCd | eval temp=coalesce(mvzip(actionCode,actionValue,"##"), "") | mvexpand temp | rex field=temp "(?&amp;lt;actionCode&amp;gt;.+)##(?&amp;lt;actionValue&amp;gt;.+)" | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See this runanywhere search with sample data&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval _raw="{
 \"timestamp\": \"2019-04-11T16:44:45.497462\",
\"payload\": {
 \"KEY_CHK_DCN_NBR\": \"19054\",
 \"recommendations\": [
 {
 \"modelName\": \"abc\",
 \"description\": \"30\",
 \"actionCode\": \"0261109614\",
 \"actionValue\": 0.027422948195084923
 },
 {
 \"modelName\": \"abc\",
 \"description\": \"30\",
 \"actionCode\": \"0261109614\",
 \"actionValue\": 0.027422948195084923
 }
 ],
 \"respCd\": \"700\",
}" | table _raw  | append [| gentimes start=-1 | eval _raw="{
 \"timestamp\": \"2019-04-11T16:44:45.497462\",
\"payload\": {
 \"KEY_CHK_DCN_NBR\": \"19054\",
 \"respCd\": \"700\",
}" | table _raw ] | spath | table payload* timestamp | rename payload.recommendations{}.* as * payload.* as *  | fields - description modelName respCd | eval temp=coalesce(mvzip(actionCode,actionValue,"##"), "") | mvexpand temp | rex field=temp "(?&amp;lt;actionCode&amp;gt;.+)##(?&amp;lt;actionValue&amp;gt;.+)" | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 12 Apr 2019 17:59:46 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2019-04-12T17:59:46Z</dc:date>
    <item>
      <title>Using MVZip and MVExpand on MultiValue fields where array sometimes doesnt exists</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-MVZip-and-MVExpand-on-MultiValue-fields-where-array/m-p/414674#M171875</link>
      <description>&lt;P&gt;{&lt;BR /&gt;
  "timestamp": "2019-04-11T16:44:45.497462",&lt;BR /&gt;
"payload": {&lt;BR /&gt;
    "KEY_CHK_DCN_NBR": "19054",&lt;BR /&gt;
      "recommendations": [&lt;BR /&gt;
      {&lt;BR /&gt;
        "modelName": "abc",&lt;BR /&gt;
        "description": "30",&lt;BR /&gt;
        "actionCode": "0261109614",&lt;BR /&gt;
        "actionValue": 0.027422948195084923&lt;BR /&gt;
      },&lt;BR /&gt;
 {&lt;BR /&gt;
        "modelName": "abc",&lt;BR /&gt;
        "description": "30",&lt;BR /&gt;
        "actionCode": "0261109614",&lt;BR /&gt;
        "actionValue": 0.027422948195084923&lt;BR /&gt;
      }&lt;BR /&gt;
    ],&lt;BR /&gt;
    "respCd": "700",&lt;BR /&gt;
}&lt;/P&gt;

&lt;P&gt;I have a api logging this information in splunk.&lt;BR /&gt;
I need to extract &lt;BR /&gt;
timestamp, payload{}.KEY_CHK_DCN_NBR, payload{}.recommendations.actionCode  and payload{}.recommendations.actionvalue&lt;/P&gt;

&lt;P&gt;i tried below, &lt;/P&gt;

&lt;P&gt;|spath output="DCN Number" path=payload.KEY_CHK_DCN_NBR&lt;BR /&gt;
|spath output=Timestamp path=timestamp&lt;BR /&gt;
|spath path=payload.recommendations{} output=r&lt;BR /&gt;
|mvexpand r&lt;BR /&gt;
|rename r as _raw&lt;BR /&gt;
|kv &lt;BR /&gt;
|rename actionCode ,actionValue &lt;BR /&gt;
|table "DCN Number" actionCode actionValue   Timestamp&lt;BR /&gt;
| search "DCN Number"!=null&lt;/P&gt;

&lt;P&gt;what happens is, in some of the request recommendation array may not be coming, still i need to capture KEY_CHK_DCN_NBR and timestamp and empty value for actioncode and actionvalue. &lt;/P&gt;

&lt;P&gt;with my try im able to get all the non-null value. &lt;/P&gt;

&lt;P&gt;can anyone help here?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:09:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-MVZip-and-MVExpand-on-MultiValue-fields-where-array/m-p/414674#M171875</guid>
      <dc:creator>rajkumarsowmy</dc:creator>
      <dc:date>2020-09-30T00:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using MVZip and MVExpand on MultiValue fields where array sometimes doesnt exists</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-MVZip-and-MVExpand-on-MultiValue-fields-where-array/m-p/414675#M171876</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | spath | table payload* timestamp | rename payload.recommendations{}.* as * payload.* as *  | fields - description modelName respCd | eval temp=coalesce(mvzip(actionCode,actionValue,"##"), "") | mvexpand temp | rex field=temp "(?&amp;lt;actionCode&amp;gt;.+)##(?&amp;lt;actionValue&amp;gt;.+)" | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;See this runanywhere search with sample data&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval _raw="{
 \"timestamp\": \"2019-04-11T16:44:45.497462\",
\"payload\": {
 \"KEY_CHK_DCN_NBR\": \"19054\",
 \"recommendations\": [
 {
 \"modelName\": \"abc\",
 \"description\": \"30\",
 \"actionCode\": \"0261109614\",
 \"actionValue\": 0.027422948195084923
 },
 {
 \"modelName\": \"abc\",
 \"description\": \"30\",
 \"actionCode\": \"0261109614\",
 \"actionValue\": 0.027422948195084923
 }
 ],
 \"respCd\": \"700\",
}" | table _raw  | append [| gentimes start=-1 | eval _raw="{
 \"timestamp\": \"2019-04-11T16:44:45.497462\",
\"payload\": {
 \"KEY_CHK_DCN_NBR\": \"19054\",
 \"respCd\": \"700\",
}" | table _raw ] | spath | table payload* timestamp | rename payload.recommendations{}.* as * payload.* as *  | fields - description modelName respCd | eval temp=coalesce(mvzip(actionCode,actionValue,"##"), "") | mvexpand temp | rex field=temp "(?&amp;lt;actionCode&amp;gt;.+)##(?&amp;lt;actionValue&amp;gt;.+)" | fields - temp
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Apr 2019 17:59:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-MVZip-and-MVExpand-on-MultiValue-fields-where-array/m-p/414675#M171876</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-04-12T17:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using MVZip and MVExpand on MultiValue fields where array sometimes doesnt exists</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-MVZip-and-MVExpand-on-MultiValue-fields-where-array/m-p/414676#M171877</link>
      <description>&lt;P&gt;Thank you very much @somesoni2 this resolved my issues!! &lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 16:00:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-MVZip-and-MVExpand-on-MultiValue-fields-where-array/m-p/414676#M171877</guid>
      <dc:creator>rajkumarsowmy</dc:creator>
      <dc:date>2019-04-15T16:00:47Z</dc:date>
    </item>
  </channel>
</rss>

