<?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: How to filter values returned from an array field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-values-returned-from-an-array-field/m-p/675449#M231105</link>
    <description>&lt;P&gt;Thanks for your reply.&amp;nbsp; It returns multiple results because there's more than one tag in the array per event.&amp;nbsp; "stats count by tags{}.name" returns 1 count for each tag.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;   os_system_name: Microsoft Windows
   os_type: Workstation
   os_vendor: Microsoft
   os_version: 22H2
   risk_score: 747.0674438476562
   severe_vulnerabilities: 1
   tags: [ [-]
     { [-]
       name: Asset_Workstation
       type: CUSTOM
     }
     { [-]
       name: Dept_Finance
       type: SITE
     }
   ]
   total_vulnerabilities: 1 &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Results:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;tags{}.name&lt;/TD&gt;&lt;TD width="50%"&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Asset_Workstation&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Dept_Finance&lt;/TD&gt;&lt;TD width="50%"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wasn't able to run eval or where operations on the tags{}.name without getting an error so I was stuck.&amp;nbsp; I just stumbled on my answer but I appreciate your time looking at this.&amp;nbsp; I knew it had to be a simple query but I wasn't initially able to put it together.&amp;nbsp; Feel free to offer a better more efficient way to get the below results.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(index="index_name") | dedup id | stats count by tags{}.name | rename tags{}.name AS dept | where (dept like "Dept_%")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Results:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;dept&lt;/TD&gt;&lt;TD width="50%"&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Dept_Finance&lt;/TD&gt;&lt;TD width="50%"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Thu, 25 Jan 2024 20:45:07 GMT</pubDate>
    <dc:creator>splguy</dc:creator>
    <dc:date>2024-01-25T20:45:07Z</dc:date>
    <item>
      <title>How to filter values returned from an array field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-values-returned-from-an-array-field/m-p/675440#M231101</link>
      <description>&lt;P&gt;I have events with an array field named "tags".&amp;nbsp; The tags array has 2 fields for each array object named "name" and "type".&amp;nbsp; I reference this array as tags{}.name.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The values being returned for one event are:&lt;BR /&gt;name, type&lt;BR /&gt;Dept_Finance, Custom&lt;BR /&gt;Asset_Workstation, Custom&lt;/P&gt;&lt;P&gt;My goal is to count the events by tags starting with "Dept_".&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;(index="index_name") | dedup id | stats count by tags{}.name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This returns the correct count of tags for "Dept_" but it's also including all other tags that do not begin with "Dept_".&amp;nbsp; The Asset_Workstation tag is attached to this event however I don't want it to output in the query.&amp;nbsp; How can I pull records with multiple tags but exclude all tags not beginning with "Dept_" from the output?&lt;/P&gt;&lt;P&gt;I know this is an easy thing to do but I'm still learning SPL.&amp;nbsp; Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2024 19:12:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-values-returned-from-an-array-field/m-p/675440#M231101</guid>
      <dc:creator>splguy</dc:creator>
      <dc:date>2024-01-25T19:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter values returned from an array field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-values-returned-from-an-array-field/m-p/675444#M231102</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;P&gt;&amp;nbsp;This returns the correct count of tags for "Dept_" but it's also including all other tags that do not begin with "Dept_".&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I don't understand this statement. &amp;nbsp;Other than groupby field &lt;FONT face="courier new,courier"&gt;tags{}.name&lt;/FONT&gt; itself, &amp;nbsp;&lt;FONT face="courier new,courier"&gt;| stats count by tags{}.name&lt;/FONT&gt; only gives one single output, that is count. &amp;nbsp;How does it "include other tags", Dept_ or not?&lt;/P&gt;&lt;P&gt;You can help us by illustrating the results you want, and the results the search actually gives you. (Anonymize as needed.) &amp;nbsp;Explain why the result is not what you expected.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2024 20:06:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-values-returned-from-an-array-field/m-p/675444#M231102</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-01-25T20:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to filter values returned from an array field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-filter-values-returned-from-an-array-field/m-p/675449#M231105</link>
      <description>&lt;P&gt;Thanks for your reply.&amp;nbsp; It returns multiple results because there's more than one tag in the array per event.&amp;nbsp; "stats count by tags{}.name" returns 1 count for each tag.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;   os_system_name: Microsoft Windows
   os_type: Workstation
   os_vendor: Microsoft
   os_version: 22H2
   risk_score: 747.0674438476562
   severe_vulnerabilities: 1
   tags: [ [-]
     { [-]
       name: Asset_Workstation
       type: CUSTOM
     }
     { [-]
       name: Dept_Finance
       type: SITE
     }
   ]
   total_vulnerabilities: 1 &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Results:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;tags{}.name&lt;/TD&gt;&lt;TD width="50%"&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Asset_Workstation&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Dept_Finance&lt;/TD&gt;&lt;TD width="50%"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wasn't able to run eval or where operations on the tags{}.name without getting an error so I was stuck.&amp;nbsp; I just stumbled on my answer but I appreciate your time looking at this.&amp;nbsp; I knew it had to be a simple query but I wasn't initially able to put it together.&amp;nbsp; Feel free to offer a better more efficient way to get the below results.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;(index="index_name") | dedup id | stats count by tags{}.name | rename tags{}.name AS dept | where (dept like "Dept_%")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Results:&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;dept&lt;/TD&gt;&lt;TD width="50%"&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;Dept_Finance&lt;/TD&gt;&lt;TD width="50%"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 25 Jan 2024 20:45:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-filter-values-returned-from-an-array-field/m-p/675449#M231105</guid>
      <dc:creator>splguy</dc:creator>
      <dc:date>2024-01-25T20:45:07Z</dc:date>
    </item>
  </channel>
</rss>

