<?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: Nested field (Json array) searching in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629112#M218525</link>
    <description>&lt;P&gt;OK, so it's not where the number of elements is&amp;nbsp;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;1&lt;FONT color="#000000"&gt;,&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#000000"&gt; but where ALL the values are the same. So, in that case do this&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval method=mvdedup('event_details{}.payment_method')
| where method="Paypal" AND mvcount(method)=1&lt;/LI-CODE&gt;&lt;P&gt;which will just remove all duplicates and them require the method match&amp;nbsp; (=Paypal) and a single variant (mvcount)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Feb 2023 10:54:08 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2023-02-01T10:54:08Z</dc:date>
    <item>
      <title>How to form query for nested field (Json array) searching?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629085#M218512</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have a field(&lt;SPAN class=""&gt;event_details&lt;/SPAN&gt;) that contains a JSON array.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Record 1:&lt;/STRONG&gt;&lt;BR /&gt;{&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;event_details&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;[{"&lt;/SPAN&gt;&lt;SPAN class=""&gt;product_id&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;P002&lt;/SPAN&gt;&lt;SPAN&gt;","&lt;/SPAN&gt;&lt;SPAN class=""&gt;price&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:19.99&lt;/SPAN&gt;&lt;SPAN&gt;,"&lt;/SPAN&gt;&lt;SPAN class=""&gt;payment_method&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;Paypal&lt;/SPAN&gt;&lt;SPAN&gt;"}]}&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG&gt;Record 2:&lt;/STRONG&gt;&lt;BR /&gt;{&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;event_details&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;[{"&lt;/SPAN&gt;&lt;SPAN class=""&gt;product_id&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;P001&lt;/SPAN&gt;&lt;SPAN&gt;","&lt;/SPAN&gt;&lt;SPAN class=""&gt;price&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:9.99&lt;/SPAN&gt;&lt;SPAN&gt;,"&lt;/SPAN&gt;&lt;SPAN class=""&gt;payment_method&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;Credit&lt;/SPAN&gt; &lt;SPAN class=""&gt;Card&lt;/SPAN&gt;&lt;SPAN&gt;"},{"&lt;/SPAN&gt;&lt;SPAN class=""&gt;product_id&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;P002&lt;/SPAN&gt;&lt;SPAN&gt;","&lt;/SPAN&gt;&lt;SPAN class=""&gt;price&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:10&lt;/SPAN&gt;&lt;SPAN&gt;,"&lt;/SPAN&gt;&lt;SPAN class=""&gt;payment_method&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;Credit&lt;/SPAN&gt; &lt;SPAN class=""&gt;Card&lt;/SPAN&gt;&lt;SPAN&gt;"}]&lt;/SPAN&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Query:&lt;/STRONG&gt;&lt;BR /&gt;source="sample_Logs.csv" host="si-i-01ab4b9a34d1f49ec.prd-p-gfp5t.splunkcloud.com" sourcetype="csv" | tojson auto(*) | spath "event_details{}.product_id" | search "event_details{}.product_id"=P002&lt;BR /&gt;&lt;BR /&gt;When using the above query I got both records in the response.&lt;/P&gt;
&lt;P&gt;But I need only those records with product_id = "P002" only and not with any other product_id in the JSON array. In this case record 1 contains only product_id as P002. I need only that record in the response.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;How to form the query for it?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Austin_James_0-1675232644960.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23651iBEB81F1F388494E8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Austin_James_0-1675232644960.png" alt="Austin_James_0-1675232644960.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really appreciate any help you can provide.&lt;BR /&gt;&lt;BR /&gt;Update: Have explained my query properly in the below comment.&lt;BR /&gt;&amp;nbsp;&lt;A href="https://community.splunk.com/t5/Splunk-Search/Nested-field-Json-array-searching/m-p/629097/highlight/true#M218519" target="_self"&gt;https://community.splunk.com/t5/Splunk-Search/Nested-field-Json-array-searching/m-p/629097/highlight/true#M218519&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 16:44:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629085#M218512</guid>
      <dc:creator>Austin_James</dc:creator>
      <dc:date>2023-02-01T16:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: Nested field (Json array) searching</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629087#M218513</link>
      <description>&lt;P&gt;Add&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| where mvcount('event_details{}.product_id')=1&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 01 Feb 2023 07:21:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629087#M218513</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-02-01T07:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: Nested field (Json array) searching</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629089#M218515</link>
      <description>&lt;P&gt;Or you can combine the search and the where to&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| where 'event_details{}.product_id'="P002" AND mvcount('event_details{}.product_id')=2&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 01 Feb 2023 07:22:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629089#M218515</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-02-01T07:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Nested field (Json array) searching</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629097#M218519</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Thanks for the response.&lt;BR /&gt;When adding the&amp;nbsp;mvcount we are adding the criteria for the JSON array to be of length one. Which does not solve my query.&lt;BR /&gt;I will explain my case better with the following example:&lt;BR /&gt;Consider the following records:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;event&lt;/TD&gt;&lt;TD&gt;event_details&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;E1&lt;/TD&gt;&lt;TD&gt;[{"product_id":"P001","price":9.99,"payment_method":"Credit Card"},{"product_id":"P002","price":10,"payment_method":"Credit Card"}]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;E2&lt;/TD&gt;&lt;TD&gt;[{"product_id":"P001","price":9.99,"payment_method":"Credit Card"},{"product_id":"P002","price":10,"payment_method":"Paypal"}]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;E3&lt;/TD&gt;&lt;TD&gt;[{"product_id":"P002","price":19.99,"payment_method":"Paypal"}]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;E4&lt;/TD&gt;&lt;TD&gt;[{"product_id":"P001","price":9.99,"payment_method":"Paypal"},{"product_id":"P002","price":10,"payment_method":"Paypal"}]&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;source="sample_Logs.csv" host="si-i-01ab4b9a34d1f49ec.prd-p-gfp5t.splunkcloud.com" sourcetype="csv" | tojson auto(*) | spath "event_details{}.payment_method" | where 'event_details{}.payment_method'="Paypal"&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;When using the above query I got 3 (E2, E3, E4) events in the response as shown in the below image.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Austin_James_0-1675238228745.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23652i7E5455B82AEBDDC3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Austin_James_0-1675238228745.png" alt="Austin_James_0-1675238228745.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to filter the events where all the purchases are done only by&amp;nbsp;Paypal. So I am expecting the events E3 and E4 alone. Neglecting the event E2 since one of the purchases has been made by Credit Card.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 08:04:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629097#M218519</guid>
      <dc:creator>Austin_James</dc:creator>
      <dc:date>2023-02-01T08:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: Nested field (Json array) searching</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629103#M218522</link>
      <description>&lt;P&gt;Splunk does not handle structure of json events. So you can't just select a particular part of a json structure by some of its fields. Or at least not directly.&lt;/P&gt;&lt;P&gt;You must first do spath to extract just the values of event_details to a multivalued field. Then you have to do mvexpand to split those values to separate events. Those events will contain separate json entities which you can treat with spath again.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 09:58:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629103#M218522</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-02-01T09:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Nested field (Json array) searching</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629112#M218525</link>
      <description>&lt;P&gt;OK, so it's not where the number of elements is&amp;nbsp;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;1&lt;FONT color="#000000"&gt;,&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#000000"&gt; but where ALL the values are the same. So, in that case do this&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval method=mvdedup('event_details{}.payment_method')
| where method="Paypal" AND mvcount(method)=1&lt;/LI-CODE&gt;&lt;P&gt;which will just remove all duplicates and them require the method match&amp;nbsp; (=Paypal) and a single variant (mvcount)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 10:54:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629112#M218525</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-02-01T10:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Nested field (Json array) searching</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629113#M218526</link>
      <description>&lt;P&gt;Here's an example showing 3 and 4 returned&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| fields - _time
| eval _raw="event	event_details
E1	[{\"product_id\":\"P001\",\"price\":9.99,\"payment_method\":\"Credit Card\"},{\"product_id\":\"P002\",\"price\":10,\"payment_method\":\"Credit Card\"}]
E2	[{\"product_id\":\"P001\",\"price\":9.99,\"payment_method\":\"Credit Card\"},{\"product_id\":\"P002\",\"price\":10,\"payment_method\":\"Paypal\"}]
E3	[{\"product_id\":\"P002\",\"price\":19.99,\"payment_method\":\"Paypal\"}]
E4	[{\"product_id\":\"P001\",\"price\":9.99,\"payment_method\":\"Paypal\"},{\"product_id\":\"P002\",\"price\":10,\"payment_method\":\"Paypal\"}]
"
| multikv forceheader=1 
| table event event_details

``` Above sets up your example dataset ```

| tojson auto(*)
| spath event_details{}.payment_method
| eval method=mvdedup('event_details{}.payment_method')
| where method="Paypal" AND mvcount(method)=1&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 01 Feb 2023 11:00:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-form-query-for-nested-field-Json-array-searching/m-p/629113#M218526</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-02-01T11:00:50Z</dc:date>
    </item>
  </channel>
</rss>

