<?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: Grouping and counting items based on values in the list in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Grouping-and-counting-items-based-on-values-in-the-list/m-p/617150#M214474</link>
    <description>&lt;P&gt;You just need to expand the multivalue field into its own events.&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;BASE_SEARCH&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| rex field=MESSAGE "(?&amp;lt;JSON&amp;gt;\{.*\})"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| spath input=JSON&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| rename Details{}.type as "Type" &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| rename errorList{} as "Error"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;| mvexpand Error&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| stats count as Count by "Type" "Error"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| table Type, Error , Count&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Oct 2022 14:58:20 GMT</pubDate>
    <dc:creator>johnhuang</dc:creator>
    <dc:date>2022-10-14T14:58:20Z</dc:date>
    <item>
      <title>Grouping and counting items based on values in the list?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-and-counting-items-based-on-values-in-the-list/m-p/617142#M214472</link>
      <description>&lt;P&gt;I have below JSON event where there are errors present in a field which is a &lt;STRONG&gt;list&lt;/STRONG&gt;. I want to extract the values in the list and group them with another field which is part of an object of the same event.&amp;nbsp; After grouping I want to count them like below output. I am using below query but not getting the expected output. Any help on this will be highly appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Sample JSON Event1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{
"errorList": ["There is an ErrorA", "There is some other ErrorB", "Ohh another ErrorC"],
"Details": {
"type": "ABC"
}
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Sample JSON Event2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{
"errorList": ["There is some other ErrorB", "Ohh another ErrorC"],
"Details": {
"type": "XYZ"
}
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Expected Output&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Type   Error                                Count
ABC    There is some other ErrorB           3
ABC    There is an ErrorA                   4
XYZ    Ohh another ErrorC                   2&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Query I am trying&amp;nbsp;&lt;/STRONG&gt;&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;BASE_SEARCH
| rex field=MESSAGE "(?&amp;lt;JSON&amp;gt;\{.*\})"
| spath input=JSON
| rename Details{}.type as "Type"  
| rename errorList{} as "Error"
| stats count as Count by "Type" "Error"
| table Type, Error , Count&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 14:57:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-and-counting-items-based-on-values-in-the-list/m-p/617142#M214472</guid>
      <dc:creator>ghostrider</dc:creator>
      <dc:date>2022-10-14T14:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping and counting items based on values in the list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-and-counting-items-based-on-values-in-the-list/m-p/617150#M214474</link>
      <description>&lt;P&gt;You just need to expand the multivalue field into its own events.&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;BASE_SEARCH&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| rex field=MESSAGE "(?&amp;lt;JSON&amp;gt;\{.*\})"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| spath input=JSON&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| rename Details{}.type as "Type" &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| rename errorList{} as "Error"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;| mvexpand Error&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| stats count as Count by "Type" "Error"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;| table Type, Error , Count&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 14:58:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-and-counting-items-based-on-values-in-the-list/m-p/617150#M214474</guid>
      <dc:creator>johnhuang</dc:creator>
      <dc:date>2022-10-14T14:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping and counting items based on values in the list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-and-counting-items-based-on-values-in-the-list/m-p/617188#M214483</link>
      <description>&lt;P&gt;Thanks!!! I ran the above query but it shows no result.&amp;nbsp; Do I need to change the order of mvexpand or need to add some other method altogether?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 19:25:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-and-counting-items-based-on-values-in-the-list/m-p/617188#M214483</guid>
      <dc:creator>ghostrider</dc:creator>
      <dc:date>2022-10-14T19:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping and counting items based on values in the list?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Grouping-and-counting-items-based-on-values-in-the-list/m-p/617229#M214499</link>
      <description>&lt;P&gt;Your data doesn't have a field named Details{}.type because Details is not an array. &amp;nbsp;Use Details.type will solve your problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;BASE_SEARCH
| rex field=MESSAGE "(?&amp;lt;JSON&amp;gt;\{.*\})"
| spath input=JSON
| rename Details.type as "Type"  
| rename errorList{} as "Error"
| stats count as Count by "Type" "Error"
| table Type, Error , Count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the sample JSON events you give, the output is&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Type&lt;/TD&gt;&lt;TD&gt;Error&lt;/TD&gt;&lt;TD&gt;Count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;Ohh another ErrorC&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;There is an ErrorA&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;There is some other ErrorB&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XYZ&lt;/TD&gt;&lt;TD&gt;Ohh another ErrorC&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XYZ&lt;/TD&gt;&lt;TD&gt;There is some other ErrorB&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;The output table you listed is not from those two datapoints. &amp;nbsp;If you want to tally by Error alone, the search should be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;BASE_SEARCH
| rex field=MESSAGE "(?&amp;lt;JSON&amp;gt;\{.*\})"
| spath input=JSON
| rename Details.type as "Type"  
| rename errorList{} as "Error"
| stats values(Type) as Type count as Count by "Error"
| table Type, Error , Count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With this, you'll get something like&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;Type&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;Error&lt;/TD&gt;&lt;TD&gt;Count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;ABC&lt;/DIV&gt;&lt;DIV class=""&gt;XYZ&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;Ohh another ErrorC&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;There is an ErrorA&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV class=""&gt;ABC&lt;/DIV&gt;&lt;DIV class=""&gt;XYZ&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;There is some other ErrorB&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sat, 15 Oct 2022 01:26:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Grouping-and-counting-items-based-on-values-in-the-list/m-p/617229#M214499</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-10-15T01:26:13Z</dc:date>
    </item>
  </channel>
</rss>

