<?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: parsing of array in splunk mvfilter in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/parsing-of-array-in-splunk-mvfilter/m-p/439248#M95828</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Can you please try below query ?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt;
| spath
| rename calls{}.* as *
| rename "context.cached" as cached
| eval temp=mvzip(call,ts), temp1=mvzip(temp,cached)
| mvexpand temp1
| eval call=mvindex(split(temp1,","),0), ts=mvindex(split(temp1,","),1), cached=mvindex(split(temp1,","),2)
| where ts&amp;lt;=3
| stats count as TotalCount, sum(eval(if(cached="true",1,0))) as TrueCount
| eval Percentage=(TrueCount/TotalCount)*100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Below is run anywhere search which is generating 3 Columns, &lt;CODE&gt;TotalCount&lt;/CODE&gt;, &lt;CODE&gt;TrueCount&lt;/CODE&gt; and &lt;CODE&gt;Percentage&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="{\"calls\":[{\"call\":\"a\",\"ts\":\"1\",\"context\":{\"cached\":\"false\"}},{\"call\":\"b\",\"ts\":\"2\",\"context\":{\"cached\":\"true\"}},{\"call\":\"c\",\"ts\":\"3\",\"context\":{\"cached\":\"true\"}},{\"call\":\"d\",\"ts\":\"4\",\"context\":{\"cached\":\"true\"}}]}"
| spath
| rename calls{}.* as *
| rename "context.cached" as cached
| eval temp=mvzip(call,ts), temp1=mvzip(temp,cached)
| mvexpand temp1
| eval call=mvindex(split(temp1,","),0), ts=mvindex(split(temp1,","),1), cached=mvindex(split(temp1,","),2)
| where ts&amp;lt;=3
| stats count as TotalCount, sum(eval(if(cached="true",1,0))) as TrueCount
| eval Percentage=(TrueCount/TotalCount)*100
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 18 Dec 2018 11:46:03 GMT</pubDate>
    <dc:creator>harsmarvania57</dc:creator>
    <dc:date>2018-12-18T11:46:03Z</dc:date>
    <item>
      <title>parsing of array in splunk mvfilter</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/parsing-of-array-in-splunk-mvfilter/m-p/439247#M95827</link>
      <description>&lt;P&gt;In my data I have rows such as this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"calls":[{"call":"a","ts":"1","context":{"cached":"false"}},{"call":"b","ts":"2","context":{"cached":"true"}},{"call":"c","ts":"3","context":{"cached":"true"}},{"call":"d","ts":"4","context":{"cached":"true"}}]}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to find the rows which happened at ts &amp;lt;= 3 and see what % of them were are cached or not &lt;/P&gt;

&lt;P&gt;I have the query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=*  | stats count | eval cutoffts=3 | eval calls="{\"calls\":[{\"call\":\"a\",\"ts\":\"1\",\"context\":{\"cached\":\"false\"}},{\"call\":\"b\",\"ts\":\"2\",\"context\":{\"cached\":\"true\"}},{\"call\":\"c\",\"ts\":\"3\",\"context\":{\"cached\":\"true\"}},{\"call\":\"d\",\"ts\":\"4\",\"context\":{\"cached\":\"true\"}}]}" | eval callsarr=spath(calls,"calls{}") | eval callsts=spath(calls, "calls{}.ts") | eval callscachedarr=spath(calls, "calls{}.context.cached") | eval callscachedarrtrue=mvcount(mvfilter(callscachedarr="true")) | eval callscachedarrfalse=mvcount(mvfilter(callscachedarr="false")) | fillnull value=0 callscachedarrtrue callscachedarrfalse | eval cachedprecentage=callscachedarrtrue/(callscachedarrtrue+callscachedarrfalse)| table calls callsarr callsts callscachedarr callscachedarrtrue callscachedarrfalse cachedprecentage
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/6259iE3815B5ADAE4BB0B/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Unfortunately, I'm unable to filter the array to only the elements that had ts &amp;lt;=3.... so i end up with 3/4 = .75 instead of 2/3=.66&lt;/P&gt;</description>
      <pubDate>Tue, 18 Dec 2018 05:07:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/parsing-of-array-in-splunk-mvfilter/m-p/439247#M95827</guid>
      <dc:creator>dtakacssplunk</dc:creator>
      <dc:date>2018-12-18T05:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: parsing of array in splunk mvfilter</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/parsing-of-array-in-splunk-mvfilter/m-p/439248#M95828</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Can you please try below query ?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt;
| spath
| rename calls{}.* as *
| rename "context.cached" as cached
| eval temp=mvzip(call,ts), temp1=mvzip(temp,cached)
| mvexpand temp1
| eval call=mvindex(split(temp1,","),0), ts=mvindex(split(temp1,","),1), cached=mvindex(split(temp1,","),2)
| where ts&amp;lt;=3
| stats count as TotalCount, sum(eval(if(cached="true",1,0))) as TrueCount
| eval Percentage=(TrueCount/TotalCount)*100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Below is run anywhere search which is generating 3 Columns, &lt;CODE&gt;TotalCount&lt;/CODE&gt;, &lt;CODE&gt;TrueCount&lt;/CODE&gt; and &lt;CODE&gt;Percentage&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="{\"calls\":[{\"call\":\"a\",\"ts\":\"1\",\"context\":{\"cached\":\"false\"}},{\"call\":\"b\",\"ts\":\"2\",\"context\":{\"cached\":\"true\"}},{\"call\":\"c\",\"ts\":\"3\",\"context\":{\"cached\":\"true\"}},{\"call\":\"d\",\"ts\":\"4\",\"context\":{\"cached\":\"true\"}}]}"
| spath
| rename calls{}.* as *
| rename "context.cached" as cached
| eval temp=mvzip(call,ts), temp1=mvzip(temp,cached)
| mvexpand temp1
| eval call=mvindex(split(temp1,","),0), ts=mvindex(split(temp1,","),1), cached=mvindex(split(temp1,","),2)
| where ts&amp;lt;=3
| stats count as TotalCount, sum(eval(if(cached="true",1,0))) as TrueCount
| eval Percentage=(TrueCount/TotalCount)*100
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Dec 2018 11:46:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/parsing-of-array-in-splunk-mvfilter/m-p/439248#M95828</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2018-12-18T11:46:03Z</dc:date>
    </item>
  </channel>
</rss>

