<?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 Count of events by field where field has multiple instances of same value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Count-of-events-by-field-where-field-has-multiple-instances-of/m-p/509481#M142383</link>
    <description>&lt;P&gt;Hi there&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;We presently have a setup where error codes are extracted and put into their own field.&amp;nbsp; The way it's been setup is that we extract all instances where it matches a certain regex pattern (e.g. "ERROR-" -&amp;gt; ERROR-1234, ERROR-5869 etc) meaning as the error code is repeated in the event we get multiple instances of the same item in the field (e.g. "ErrorField" = ERROR-1234, ERROR-1234, ERROR-5869).&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Doing 'stats count by ErrorField' seems to return all items, even the ones that are repeated as we'd get ERROR-1234 = 700 on the stats count, but a simple search where ErrorField=ERROR-1234 returns say 300 events only.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I've tried to come up with a way to filter out the duplicates in the search but have so far come up short.&amp;nbsp; My two possibles are creating a table of field instances, and then using that to launch a second search, or performing a sub search to capture the unique fields that are then used to count the events by field.&amp;nbsp; What I have so far is as follows:&lt;BR /&gt;&lt;BR /&gt;index=index ErrorField="*"&lt;BR /&gt;| stats count by ErrorField&lt;BR /&gt;| replace ERROR-X-* with ERROR-X- in&amp;nbsp;ErrorField&lt;BR /&gt;| where count &amp;gt; 200 AND ErrorField!="ERROR-X-"&lt;BR /&gt;| table ErrorField&lt;BR /&gt;&lt;BR /&gt;In short I've got a search that counts, then does a replace/where to weed out values below a certain threshold/don't match a certain criteria then putting what remains in a table.&amp;nbsp; It's the results from this table I want to use in the next search and count the total events for each item in that table, but have so far failed to be able to do this.&lt;BR /&gt;&lt;BR /&gt;Is this possible to do, and is there a right way to do this, either continuing with the method above or using a subsearch?&amp;nbsp; Alternately is it possible to remove duplicates in the original field extraction so this isn't necessary?&amp;nbsp; Although that option may not be possible as the field extraction isn't handled by ourselves and I can't say too much about it.&lt;BR /&gt;&lt;BR /&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Thu, 16 Jul 2020 09:13:23 GMT</pubDate>
    <dc:creator>djohnson99</dc:creator>
    <dc:date>2020-07-16T09:13:23Z</dc:date>
    <item>
      <title>Count of events by field where field has multiple instances of same value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-of-events-by-field-where-field-has-multiple-instances-of/m-p/509481#M142383</link>
      <description>&lt;P&gt;Hi there&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;We presently have a setup where error codes are extracted and put into their own field.&amp;nbsp; The way it's been setup is that we extract all instances where it matches a certain regex pattern (e.g. "ERROR-" -&amp;gt; ERROR-1234, ERROR-5869 etc) meaning as the error code is repeated in the event we get multiple instances of the same item in the field (e.g. "ErrorField" = ERROR-1234, ERROR-1234, ERROR-5869).&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Doing 'stats count by ErrorField' seems to return all items, even the ones that are repeated as we'd get ERROR-1234 = 700 on the stats count, but a simple search where ErrorField=ERROR-1234 returns say 300 events only.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I've tried to come up with a way to filter out the duplicates in the search but have so far come up short.&amp;nbsp; My two possibles are creating a table of field instances, and then using that to launch a second search, or performing a sub search to capture the unique fields that are then used to count the events by field.&amp;nbsp; What I have so far is as follows:&lt;BR /&gt;&lt;BR /&gt;index=index ErrorField="*"&lt;BR /&gt;| stats count by ErrorField&lt;BR /&gt;| replace ERROR-X-* with ERROR-X- in&amp;nbsp;ErrorField&lt;BR /&gt;| where count &amp;gt; 200 AND ErrorField!="ERROR-X-"&lt;BR /&gt;| table ErrorField&lt;BR /&gt;&lt;BR /&gt;In short I've got a search that counts, then does a replace/where to weed out values below a certain threshold/don't match a certain criteria then putting what remains in a table.&amp;nbsp; It's the results from this table I want to use in the next search and count the total events for each item in that table, but have so far failed to be able to do this.&lt;BR /&gt;&lt;BR /&gt;Is this possible to do, and is there a right way to do this, either continuing with the method above or using a subsearch?&amp;nbsp; Alternately is it possible to remove duplicates in the original field extraction so this isn't necessary?&amp;nbsp; Although that option may not be possible as the field extraction isn't handled by ourselves and I can't say too much about it.&lt;BR /&gt;&lt;BR /&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jul 2020 09:13:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-of-events-by-field-where-field-has-multiple-instances-of/m-p/509481#M142383</guid>
      <dc:creator>djohnson99</dc:creator>
      <dc:date>2020-07-16T09:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: Count of events by field where field has multiple instances of same value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-of-events-by-field-where-field-has-multiple-instances-of/m-p/511291#M143284</link>
      <description>&lt;P&gt;Are you sure that these are duplicates&lt;/P&gt;&lt;P&gt;If your ErrorField is a multivalue field then doing the stats count by will count by each of the values of the MV field&lt;/P&gt;&lt;P&gt;So, it's simple to remove duplicates with&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval ErrorField=mvdedup(ErrorField)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;If the ErrorField is not multivalue (I am not sure how you would get your results if it is a simple string with comma separated values) then you could do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval ErrorField=mvdedup(split(ErrorField,","))&lt;/LI-CODE&gt;&lt;P&gt;Hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 10:19:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-of-events-by-field-where-field-has-multiple-instances-of/m-p/511291#M143284</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2020-07-28T10:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Count of events by field where field has multiple instances of same value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-of-events-by-field-where-field-has-multiple-instances-of/m-p/511948#M143557</link>
      <description>&lt;P&gt;That is tremendously simple and I can't believe that was it needed.&amp;nbsp; Thank you for this!&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final query is now:&lt;BR /&gt;&lt;BR /&gt;index=index ErrorField="*"&lt;BR /&gt;| eval ErrorField=mvdedup(ErrorField)&lt;BR /&gt;| stats count by ErrorField&lt;BR /&gt;| replace ERROR-X-* with ERROR-X- in ErrorField&lt;BR /&gt;| where count &amp;gt; 200 AND ErrorField!="ERROR-X-"&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 16:07:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-of-events-by-field-where-field-has-multiple-instances-of/m-p/511948#M143557</guid>
      <dc:creator>djohnson99</dc:creator>
      <dc:date>2020-07-31T16:07:14Z</dc:date>
    </item>
  </channel>
</rss>

