<?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 Query to return events when all the objects of an array where a field value is equal to a certain value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682316#M233107</link>
    <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I need help with a splunk query to return events where an array of object contains certain value for a key in all the objects of an array&lt;/P&gt;&lt;PRE&gt;Event 1: { 
            list: [ 
                    {"name": "Hello", "type": "code"}, 
                    {"name": "Hello", "type": "document"}
                   ] 
         } 
Event 2: { 
            list: [ 
                    {"name": "Hello", "type": "code"}, 
                    {"name": "World", "type": "document"}
                   ] 
         } 
Event 3: { 
            list: [ 
                    {"name": "Hello", "type": "document"}, 
                    {"name": "Hello", "type": "document"}
                   ] 
         } &lt;/PRE&gt;&lt;P&gt;filters: In the list array,&lt;/P&gt;&lt;P&gt;the first object in an array should have "type": "code"&lt;/P&gt;&lt;P&gt;In all the items in the list array should have "name": "Hello"&lt;/P&gt;&lt;P&gt;Expected output: In the above list of events the query should return 'Event 1', where first item - list[0].type = code and list has all the items with "name": "Hello"&lt;/P&gt;&lt;P&gt;I tried multiple ways like search&lt;/P&gt;&lt;P&gt;list{}.name="Hello" This was returning the events which had atleast 1 element having name: Hello&lt;/P&gt;&lt;P&gt;However i was able to achieve checking for 1st filter as below&lt;/P&gt;&lt;P&gt;&lt;EM&gt;| eval conflict = mvindex(list, 0) | spath input=conflict | search type=code&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If someone can help in achieving both the filters in a query that will be helpful. Thanks in advance&lt;/P&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 28 Mar 2024 17:03:23 GMT</pubDate>
    <dc:creator>rajesh143rs</dc:creator>
    <dc:date>2024-03-28T17:03:23Z</dc:date>
    <item>
      <title>Query to return events when all the objects of an array where a field value is equal to a certain value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682316#M233107</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I need help with a splunk query to return events where an array of object contains certain value for a key in all the objects of an array&lt;/P&gt;&lt;PRE&gt;Event 1: { 
            list: [ 
                    {"name": "Hello", "type": "code"}, 
                    {"name": "Hello", "type": "document"}
                   ] 
         } 
Event 2: { 
            list: [ 
                    {"name": "Hello", "type": "code"}, 
                    {"name": "World", "type": "document"}
                   ] 
         } 
Event 3: { 
            list: [ 
                    {"name": "Hello", "type": "document"}, 
                    {"name": "Hello", "type": "document"}
                   ] 
         } &lt;/PRE&gt;&lt;P&gt;filters: In the list array,&lt;/P&gt;&lt;P&gt;the first object in an array should have "type": "code"&lt;/P&gt;&lt;P&gt;In all the items in the list array should have "name": "Hello"&lt;/P&gt;&lt;P&gt;Expected output: In the above list of events the query should return 'Event 1', where first item - list[0].type = code and list has all the items with "name": "Hello"&lt;/P&gt;&lt;P&gt;I tried multiple ways like search&lt;/P&gt;&lt;P&gt;list{}.name="Hello" This was returning the events which had atleast 1 element having name: Hello&lt;/P&gt;&lt;P&gt;However i was able to achieve checking for 1st filter as below&lt;/P&gt;&lt;P&gt;&lt;EM&gt;| eval conflict = mvindex(list, 0) | spath input=conflict | search type=code&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If someone can help in achieving both the filters in a query that will be helpful. Thanks in advance&lt;/P&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 28 Mar 2024 17:03:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682316#M233107</guid>
      <dc:creator>rajesh143rs</dc:creator>
      <dc:date>2024-03-28T17:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Query to return events when all the objects of an array where a field value is equal to a certain value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682328#M233109</link>
      <description>&lt;P&gt;Here is an idea: Select events in which list{}.name has one unique value "Hello", and has a value of "code" as the first element of list{}.type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| where mvindex('list{}.type', 0) == "code" AND 'list{}.name' == "Hello" AND mvcount(mvdedup('list{}.name')) == 1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, given that list is an array, selecting only the first element for matching may not be what the use case demands. (Work with developers to figure out what semantics array order may convey.) &amp;nbsp;Here is one to select any element with value "code".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| where 'list{}.type' == "code" AND 'list{}.name' == "Hello" AND mvcount(mvdedup('list{}.name')) == 1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an emulation of your mock data for you to play with and compare with real data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| fields - _*
| eval data = mvappend("{ 
            \"list\": [ 
                    {\"name\": \"Hello\", \"type\": \"code\"}, 
                    {\"name\": \"Hello\", \"type\": \"document\"}
                   ] 
         }",
"{ 
            \"list\": [ 
                    {\"name\": \"Hello\", \"type\": \"code\"}, 
                    {\"name\": \"World\", \"type\": \"document\"}
                   ] 
         }",
"{ 
            \"list\": [ 
                    {\"name\": \"Hello\", \"type\": \"document\"}, 
                    {\"name\": \"Hello\", \"type\": \"document\"}
                   ] 
         }")
| mvexpand data
| rename data AS _raw
| spath
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With this data, output is the same for both variants&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;_raw&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;list{}.name&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;list{}.type&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;{ "list": [ {"name": "Hello", "type": "code"}, {"name": "Hello", "type": "document"} ] }&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;Hello&lt;/DIV&gt;&lt;DIV class=""&gt;Hello&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;code&lt;/DIV&gt;&lt;DIV class=""&gt;document&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 28 Mar 2024 18:51:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682328#M233109</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-03-28T18:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Query to return events when all the objects of an array where a field value is equal to a certain value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682348#M233125</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;, Thanks for the response&lt;BR /&gt;the first query, as you have mentioned it 'Select events in&amp;nbsp;&lt;SPAN&gt;which list{}.name has one unique value "Hello" '&lt;BR /&gt;is there a way select events in which all the objects should contain name == "Hello" instead of just one unique value?&lt;BR /&gt;&lt;BR /&gt;To clarify about your query - 'given that list is an array, selecting only the first element for matching may not be what the use case demands'&lt;BR /&gt;I understand that it sounds weird&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;, but our use case is about selecting events where the first object in an array/list should have&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;type == "code"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2024 00:59:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682348#M233125</guid>
      <dc:creator>rajesh143rs</dc:creator>
      <dc:date>2024-03-29T00:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Query to return events when all the objects of an array where a field value is equal to a certain value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682350#M233127</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;SPAN&gt;To clarify about your query - 'given that list is an array, selecting only the first element for matching may not be what the use case demands'&lt;BR /&gt;I understand that it sounds weird&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;, but our use case is about selecting events where the first object in an array/list should have&amp;nbsp;&lt;/SPAN&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;type == "code"&lt;/FONT&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;What I was trying to say is: Do you select this one, when type == "code" is the second element?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{ 
  list: [
    {"name": "Hello", "type": "document"},
    {"name": "Hello", "type": "code"}
  ]
}&lt;/LI-CODE&gt;&lt;P&gt;If you want to select this kind of events as well as the other kind, only the second search will work. &amp;nbsp;If you want to select an event only if its first element contains type == "code", use the first search.&lt;/P&gt;&lt;BLOCKQUOTE&gt;the first query, as you have mentioned it 'Select events in&amp;nbsp;&lt;SPAN&gt;which list{}.name has one unique value "Hello" '&lt;BR /&gt;is there a way select events in which all the objects should contain name == "Hello" instead of just one unique value?&lt;/SPAN&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This gets confusing. &amp;nbsp;My rephrasing "has &lt;EM&gt;one unique&lt;/EM&gt; value 'Hello'" is based on your OP statement&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;P&gt;&lt;SPAN&gt;In &lt;EM&gt;&lt;STRONG&gt;all&lt;/STRONG&gt;&lt;/EM&gt; the items in the list array should have "name": "Hello"&lt;/SPAN&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Did I misunderstand this?&lt;/P&gt;&lt;P&gt;Anyway, my searches do retrieve Event 1 as expected. &amp;nbsp;Is there any problem with them?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2024 02:45:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682350#M233127</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-03-29T02:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: Query to return events when all the objects of an array where a field value is equal to a certain value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682353#M233128</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;, Thanks a lot, your query works &lt;span class="lia-unicode-emoji" title=":folded_hands:"&gt;🙏&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2024 03:14:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682353#M233128</guid>
      <dc:creator>rajesh143rs</dc:creator>
      <dc:date>2024-03-29T03:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: Query to return events when all the objects of an array where a field value is equal to a certain value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682354#M233129</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;There was a misunderstanding from my end about the query.&lt;BR /&gt;Your suggested query works great. Thanks again&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2024 03:18:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Query-to-return-events-when-all-the-objects-of-an-array-where-a/m-p/682354#M233129</guid>
      <dc:creator>rajesh143rs</dc:creator>
      <dc:date>2024-03-29T03:18:52Z</dc:date>
    </item>
  </channel>
</rss>

