<?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 get distinct values and their counts from fields arrays in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-distinct-values-and-their-counts-from-fields-arrays/m-p/751884#M242566</link>
    <description>&lt;P&gt;I got a stream of events in a following format:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[
  {
    "name": "event 1"
    "attributes": ["a", "b"],
  },
  {
    "name": "event 2"
    "attributes": ["a", "c"],
  }
]&lt;/LI-CODE&gt;&lt;P&gt;I am looking to aggregate them in a following way:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;a | 2
b | 1
c | 1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The list is sorted in a descending order with counts for each unique entry in the attributes array.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Aug 2025 05:40:33 GMT</pubDate>
    <dc:creator>karol</dc:creator>
    <dc:date>2025-08-20T05:40:33Z</dc:date>
    <item>
      <title>How to get distinct values and their counts from fields arrays</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-distinct-values-and-their-counts-from-fields-arrays/m-p/751884#M242566</link>
      <description>&lt;P&gt;I got a stream of events in a following format:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[
  {
    "name": "event 1"
    "attributes": ["a", "b"],
  },
  {
    "name": "event 2"
    "attributes": ["a", "c"],
  }
]&lt;/LI-CODE&gt;&lt;P&gt;I am looking to aggregate them in a following way:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;a | 2
b | 1
c | 1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The list is sorted in a descending order with counts for each unique entry in the attributes array.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 05:40:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-distinct-values-and-their-counts-from-fields-arrays/m-p/751884#M242566</guid>
      <dc:creator>karol</dc:creator>
      <dc:date>2025-08-20T05:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get distinct values and their counts from fields arrays</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-distinct-values-and-their-counts-from-fields-arrays/m-p/751885#M242567</link>
      <description>&lt;P&gt;Is this part of a json structure? Assuming it is, you could do something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="{
\"array\": [
  {
    \"name\": \"event 1\",
    \"attributes\": [\"a\", \"b\"]
  },
  {
    \"name\": \"event 2\",
    \"attributes\": [\"a\", \"c\"]
  }
]}"
``` The lines above simulate something like the data you shared ```
| spath array{} output=array
| mvexpand array
| spath input=array attributes{} output=attributes
| stats count by attributes
| sort 0 -count&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 20 Aug 2025 05:56:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-distinct-values-and-their-counts-from-fields-arrays/m-p/751885#M242567</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2025-08-20T05:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to get distinct values and their counts from fields arrays</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-distinct-values-and-their-counts-from-fields-arrays/m-p/751889#M242568</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/312487"&gt;@karol&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With JSON array, you can use below.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval raw="[{\"name\":\"event 1\", \"attributes\":[\"a\",\"b\"]}, {\"name\":\"event 2\", \"attributes\":[\"a\",\"c\"]}]"
| spath input=raw path={} output=events
| mvexpand events
| spath input=events path=attributes{} output=attribute
| stats count by attribute
| sort - count&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="demo3.JPG" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/40004i27940563406BFBC4/image-size/large?v=v2&amp;amp;px=999" role="button" title="demo3.JPG" alt="demo3.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Prewin&lt;BR /&gt;If this answer helped you, please consider marking it as the solution or giving a Karma. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 06:11:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-distinct-values-and-their-counts-from-fields-arrays/m-p/751889#M242568</guid>
      <dc:creator>PrewinThomas</dc:creator>
      <dc:date>2025-08-20T06:11:08Z</dc:date>
    </item>
  </channel>
</rss>

