<?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 search by value from a json list? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-search-by-value-from-a-json-list/m-p/613557#M213243</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider this event structure :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;{"result" : {"dogs" : [{"name" : "dog-a", "food":["pizza", "burger"] },
{"name" : "dog-b", "food":["pasta"] }] }}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now want to filter the dogs by name and present them relevant food.&lt;/P&gt;
&lt;P&gt;When I try this search(with the relevant index):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;result.dogs{}.name = dog_a| table result.dogs{}.food{}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I Am getting this result:&lt;/P&gt;
&lt;P&gt;pizza&lt;/P&gt;
&lt;P&gt;burger&lt;/P&gt;
&lt;P&gt;pasta&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I Am expecting to get only dog-a foods(pizza and burger)&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Sep 2022 15:39:15 GMT</pubDate>
    <dc:creator>mottig</dc:creator>
    <dc:date>2022-09-19T15:39:15Z</dc:date>
    <item>
      <title>How to filter search by value from a json list?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-search-by-value-from-a-json-list/m-p/613557#M213243</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider this event structure :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;{"result" : {"dogs" : [{"name" : "dog-a", "food":["pizza", "burger"] },
{"name" : "dog-b", "food":["pasta"] }] }}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now want to filter the dogs by name and present them relevant food.&lt;/P&gt;
&lt;P&gt;When I try this search(with the relevant index):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;result.dogs{}.name = dog_a| table result.dogs{}.food{}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I Am getting this result:&lt;/P&gt;
&lt;P&gt;pizza&lt;/P&gt;
&lt;P&gt;burger&lt;/P&gt;
&lt;P&gt;pasta&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I Am expecting to get only dog-a foods(pizza and burger)&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2022 15:39:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-search-by-value-from-a-json-list/m-p/613557#M213243</guid>
      <dc:creator>mottig</dc:creator>
      <dc:date>2022-09-19T15:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Filter search by value from a json list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-search-by-value-from-a-json-list/m-p/613581#M213249</link>
      <description>&lt;P&gt;The quick and dirty method going on the exact event format in your query is to run regex and create new lines per dog.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=_raw "dogs\" : \[(?&amp;lt;dogs_raw&amp;gt;.+)\] " 
| eval new_dogs=split(replace(dogs_raw, "},{", "}##{"), "##")
| mvexpand new_dogs
| spath input=new_dogs
| search name="dog-a" 
| table food{}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lines 1&amp;amp;2 extracts everything from "dogs" and splits them out into a multivalue field called new_dogs.&lt;BR /&gt;Lines 3&amp;amp;4 expands them out to one row per dog and extracts the fields.&lt;BR /&gt;&lt;BR /&gt;If this is a datasource you'll be using a lot and other users will be looking at it, it might be worth tweaking your input to split each dog into its own event which would make lines 1-4 redundant.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2022 10:44:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-search-by-value-from-a-json-list/m-p/613581#M213249</guid>
      <dc:creator>andrew_nelson</dc:creator>
      <dc:date>2022-09-19T10:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: Filter search by value from a json list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-search-by-value-from-a-json-list/m-p/613587#M213252</link>
      <description>&lt;P&gt;Hi thank you for your answer.&lt;/P&gt;&lt;P&gt;When I Am running the search I Am getting a warning that -&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;Field 'new_dogs' does not exist in the data.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2022 11:22:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-search-by-value-from-a-json-list/m-p/613587#M213252</guid>
      <dc:creator>mottig</dc:creator>
      <dc:date>2022-09-19T11:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter search by value from a json list?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-search-by-value-from-a-json-list/m-p/613684#M213287</link>
      <description>&lt;P&gt;You want to access structured result.dogs{}, instead of operating on result.dogs{}.name directly, because you want to apply&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Mvexpand" target="_blank" rel="noopener"&gt;mvexpand&lt;/A&gt;&amp;nbsp;to the structure. &amp;nbsp;Internal structure of JSON can be accessed with path option in &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Spath" target="_blank" rel="noopener"&gt;spath&lt;/A&gt;. &amp;nbsp;After mvexpand, you then extract inner fields using spath. (Yes, again.) &amp;nbsp;Try this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path=result.dogs{}
| mvexpand result.dogs{}
| spath input=result.dogs{}
| where name == "dog-a"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Output from your sample data is&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;food{}&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;name&lt;/TD&gt;&lt;TD&gt;result.dogs{}&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;pizza&lt;/DIV&gt;&lt;DIV class=""&gt;burger&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;dog-a&lt;/TD&gt;&lt;TD&gt;{"name" : "dog-a", "food":["pizza", "burger"] }&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 20 Sep 2022 05:19:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-search-by-value-from-a-json-list/m-p/613684#M213287</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-09-20T05:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter search by value from a json list?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-search-by-value-from-a-json-list/m-p/613709#M213296</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Thank you for your answer.&lt;/P&gt;&lt;P&gt;It worked like a magic&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 06:56:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-search-by-value-from-a-json-list/m-p/613709#M213296</guid>
      <dc:creator>mottig</dc:creator>
      <dc:date>2022-09-20T06:56:41Z</dc:date>
    </item>
  </channel>
</rss>

