<?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 filter an array element based two fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-an-array-element-based-two-fields/m-p/141207#M39089</link>
    <description>&lt;P&gt;I am trying to get all the event within the 'browsers' field there is an element with name=IE &amp;amp;&amp;amp; data!=null&lt;/P&gt;

&lt;P&gt;here is an example of the event. The order of those browsers can be anything. Some browser may have not data field.&lt;/P&gt;

&lt;P&gt;1 How do I find those events that has this kind of element in 'browsers'&lt;BR /&gt;
2 How do I extract the 'data' field of particular browser, like IE&lt;/P&gt;

&lt;P&gt;browsers[&lt;/P&gt;

&lt;P&gt;{  name: firefox&lt;BR /&gt;
   data:[&lt;BR /&gt;
   {&lt;BR /&gt;
   usage: 10&lt;BR /&gt;
   time: 200&lt;BR /&gt;
   }&lt;BR /&gt;
  ]&lt;BR /&gt;
},&lt;/P&gt;

&lt;P&gt;{  name: IE&lt;BR /&gt;
   data:[&lt;BR /&gt;
   {&lt;BR /&gt;
   usage: 30&lt;BR /&gt;
   time: 400&lt;BR /&gt;
   },&lt;BR /&gt;
   {&lt;BR /&gt;
   usage: 20&lt;BR /&gt;
   time: 500&lt;BR /&gt;
   }&lt;BR /&gt;
  ]&lt;BR /&gt;
},&lt;/P&gt;

&lt;P&gt;{  name: Chrome&lt;BR /&gt;
},&lt;BR /&gt;
….&lt;/P&gt;

&lt;P&gt;]&lt;/P&gt;</description>
    <pubDate>Wed, 23 Apr 2014 23:14:41 GMT</pubDate>
    <dc:creator>jiangxue</dc:creator>
    <dc:date>2014-04-23T23:14:41Z</dc:date>
    <item>
      <title>How to filter an array element based two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-an-array-element-based-two-fields/m-p/141207#M39089</link>
      <description>&lt;P&gt;I am trying to get all the event within the 'browsers' field there is an element with name=IE &amp;amp;&amp;amp; data!=null&lt;/P&gt;

&lt;P&gt;here is an example of the event. The order of those browsers can be anything. Some browser may have not data field.&lt;/P&gt;

&lt;P&gt;1 How do I find those events that has this kind of element in 'browsers'&lt;BR /&gt;
2 How do I extract the 'data' field of particular browser, like IE&lt;/P&gt;

&lt;P&gt;browsers[&lt;/P&gt;

&lt;P&gt;{  name: firefox&lt;BR /&gt;
   data:[&lt;BR /&gt;
   {&lt;BR /&gt;
   usage: 10&lt;BR /&gt;
   time: 200&lt;BR /&gt;
   }&lt;BR /&gt;
  ]&lt;BR /&gt;
},&lt;/P&gt;

&lt;P&gt;{  name: IE&lt;BR /&gt;
   data:[&lt;BR /&gt;
   {&lt;BR /&gt;
   usage: 30&lt;BR /&gt;
   time: 400&lt;BR /&gt;
   },&lt;BR /&gt;
   {&lt;BR /&gt;
   usage: 20&lt;BR /&gt;
   time: 500&lt;BR /&gt;
   }&lt;BR /&gt;
  ]&lt;BR /&gt;
},&lt;/P&gt;

&lt;P&gt;{  name: Chrome&lt;BR /&gt;
},&lt;BR /&gt;
….&lt;/P&gt;

&lt;P&gt;]&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2014 23:14:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-an-array-element-based-two-fields/m-p/141207#M39089</guid>
      <dc:creator>jiangxue</dc:creator>
      <dc:date>2014-04-23T23:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter an array element based two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-an-array-element-based-two-fields/m-p/141208#M39090</link>
      <description>&lt;P&gt;Hi jiangxue,&lt;/P&gt;

&lt;P&gt;try something like this run everywhere search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal | head 1 | eval foo="browsers[ {  name: firefox
   data:[
   {
   usage: 10
   time: 200
   }
  ]
},

{  name: IE
   data:[
   {
   usage: 30
   time: 400
   },
   {
   usage: 20
   time: 500
   }
  ]
},

{  name: Chrome
},
….

]" 
| rex max_match=0 field=foo "name:\s(?&amp;lt;myBrowser&amp;gt;.+)\s" 
| rex max_match=0 field=foo "usage:\s(?&amp;lt;myUsage&amp;gt;.+)\s" 
| table myBrowser myUsage 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the first part is only to setup the test field called foo, based on your example.&lt;/P&gt;

&lt;P&gt;The two following regex's will get you two new fields called &lt;CODE&gt;myBroswer&lt;/CODE&gt; and &lt;CODE&gt;myUsage&lt;/CODE&gt;. Set this up as &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.3/Knowledge/Addfieldsatsearchtime"&gt;automatic field extraction&lt;/A&gt; and do your stats on it.&lt;/P&gt;

&lt;P&gt;I also tried &lt;CODE&gt;spath&lt;/CODE&gt; but did not get any useful output, so I used &lt;CODE&gt;rex&lt;/CODE&gt; instead&lt;/P&gt;

&lt;P&gt;hope this hepls to get you going ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2014 08:42:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-an-array-element-based-two-fields/m-p/141208#M39090</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-04-24T08:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter an array element based two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-an-array-element-based-two-fields/m-p/141209#M39091</link>
      <description>&lt;P&gt;You're not getting anything useful with &lt;CODE&gt;spath&lt;/CODE&gt; because this is neither JSON nor XML.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2014 11:41:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-an-array-element-based-two-fields/m-p/141209#M39091</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-04-24T11:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter an array element based two fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-an-array-element-based-two-fields/m-p/141210#M39092</link>
      <description>&lt;P&gt;thx @martin_mueller I knew that. &lt;BR /&gt;
I wrote it because I was curious myself if the &lt;CODE&gt;spath&lt;/CODE&gt; command can do some hidden magic and handle this almost JSON like output just the same &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2014 12:08:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-an-array-element-based-two-fields/m-p/141210#M39092</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-04-24T12:08:00Z</dc:date>
    </item>
  </channel>
</rss>

