<?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: group by index and count in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173441#M49741</link>
    <description>&lt;P&gt;You have a couple of choices. &lt;BR /&gt;
You can use the |metadata command (quickest)  detailed &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.3/SearchReference/Metadata"&gt;here&lt;/A&gt;&lt;BR /&gt;
if either the sourcetype or sources are unique. It returns type=host or type=sources or type=sourcetype.&lt;BR /&gt;
given what the "collections" look like, this would be fine as long as you have one source per collection.&lt;BR /&gt;
Otherwise you'll need to pipe to a stats command and perhaps use an eval to combine them.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;|metadata type=sources index=coll*&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Since cleaning that up might be more complex than your current Splunk knowledge allows...  you can do this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=coll* |stats count by index|sort -count&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Which will take longer to return (depending on the timeframe, i.e. how many collections you're covering) but it will give you what you want. If you want to sort by something else... change the field in the &lt;CODE&gt;|sort -{field}&lt;/CODE&gt; section.  remove the &lt;CODE&gt;-&lt;/CODE&gt; or switch it out for a &lt;CODE&gt;+&lt;/CODE&gt; if you want the count to sort ascending... &lt;/P&gt;</description>
    <pubDate>Wed, 06 May 2015 22:06:27 GMT</pubDate>
    <dc:creator>rsennett_splunk</dc:creator>
    <dc:date>2015-05-06T22:06:27Z</dc:date>
    <item>
      <title>group by index and count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173439#M49739</link>
      <description>&lt;P&gt;Hi, I have several collections:&lt;BR /&gt;
coll_2015_01_01, coll_2015_01_02, coll_2015_01_03, coll_2015_01_04 ...&lt;BR /&gt;
I want to write a query:&lt;/P&gt;

&lt;P&gt;index=coll_2015_01_01 | group by $indexname count&lt;BR /&gt;
and get:&lt;BR /&gt;
coll_2015_01_01   123&lt;BR /&gt;
coll_2015_01_02   234&lt;BR /&gt;
coll_2015_01_03   333&lt;BR /&gt;
coll_2015_01_04   555&lt;BR /&gt;
coll_2015_01_05   444&lt;/P&gt;

&lt;P&gt;count of entries in each collection. Can I do it using splunk?&lt;BR /&gt;
...&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:45:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173439#M49739</guid>
      <dc:creator>seregaserega</dc:creator>
      <dc:date>2020-09-28T19:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: group by index and count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173440#M49740</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=coll* | stats count by index
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 May 2015 21:53:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173440#M49740</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-05-06T21:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: group by index and count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173441#M49741</link>
      <description>&lt;P&gt;You have a couple of choices. &lt;BR /&gt;
You can use the |metadata command (quickest)  detailed &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.3/SearchReference/Metadata"&gt;here&lt;/A&gt;&lt;BR /&gt;
if either the sourcetype or sources are unique. It returns type=host or type=sources or type=sourcetype.&lt;BR /&gt;
given what the "collections" look like, this would be fine as long as you have one source per collection.&lt;BR /&gt;
Otherwise you'll need to pipe to a stats command and perhaps use an eval to combine them.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;|metadata type=sources index=coll*&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Since cleaning that up might be more complex than your current Splunk knowledge allows...  you can do this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=coll* |stats count by index|sort -count&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Which will take longer to return (depending on the timeframe, i.e. how many collections you're covering) but it will give you what you want. If you want to sort by something else... change the field in the &lt;CODE&gt;|sort -{field}&lt;/CODE&gt; section.  remove the &lt;CODE&gt;-&lt;/CODE&gt; or switch it out for a &lt;CODE&gt;+&lt;/CODE&gt; if you want the count to sort ascending... &lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2015 22:06:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173441#M49741</guid>
      <dc:creator>rsennett_splunk</dc:creator>
      <dc:date>2015-05-06T22:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: group by index and count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173442#M49742</link>
      <description>&lt;P&gt;For this type of search you're better off using &lt;CODE&gt;tstats&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count where index=coll* by index
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Should be about two orders of magnitude faster if my home Splunk is a good indicator.&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2015 22:45:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173442#M49742</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-05-06T22:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: group by index and count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173443#M49743</link>
      <description>&lt;P&gt;Good point, Martin... Make that an answer so  seregaserega can accept the best one. I always forget &lt;CODE&gt;|tstats&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2015 22:48:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173443#M49743</guid>
      <dc:creator>rsennett_splunk</dc:creator>
      <dc:date>2015-05-06T22:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: group by index and count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173444#M49744</link>
      <description>&lt;P&gt;Great thank you!&lt;BR /&gt;
It works, thanks for the detailed explanation, useful.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 09:05:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173444#M49744</guid>
      <dc:creator>seregaserega</dc:creator>
      <dc:date>2015-05-07T09:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: group by index and count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173445#M49745</link>
      <description>&lt;P&gt;All answers works, I've accepted the longest &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 09:06:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173445#M49745</guid>
      <dc:creator>seregaserega</dc:creator>
      <dc:date>2015-05-07T09:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: group by index and count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173446#M49746</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;|metadata type=sources index=coll*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;returns nothing unfortunately&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|metadata type=sources index=*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;returns hadoop index based on hadoop provider. My coll* virtual indexes are based on mongo. I use mongo provider &lt;A href="https://splunkbase.splunk.com/app/1810/#/documentation"&gt;https://splunkbase.splunk.com/app/1810/#/documentation&lt;/A&gt;&lt;BR /&gt;
to get access to mongo data using Hunk&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 09:42:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173446#M49746</guid>
      <dc:creator>seregaserega</dc:creator>
      <dc:date>2015-05-07T09:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: group by index and count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173447#M49747</link>
      <description>&lt;P&gt;It works for indexes using hadoop-provider. It doesn't work for indexes based on mongo-provider&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 10:17:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173447#M49747</guid>
      <dc:creator>seregaserega</dc:creator>
      <dc:date>2015-05-07T10:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: group by index and count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173448#M49748</link>
      <description>&lt;P&gt;@ seregaserega &lt;BR /&gt;
In Splunk, an index is an index. So, you want to double-check that there isn't something slightly different about the names of the indexes holding 'hadoop-provider' and 'mongo-provider' data. if the names are not collSOMETHINGELSE it won't match.&lt;/P&gt;

&lt;P&gt;@Martin_Mueller&lt;BR /&gt;
All answers were correct, but yours is the most efficient. So I'm gonna go upvote the heck out of your stuff for the equiv Karma points. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 15:47:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173448#M49748</guid>
      <dc:creator>rsennett_splunk</dc:creator>
      <dc:date>2015-05-07T15:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: group by index and count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173449#M49749</link>
      <description>&lt;P&gt;This is intended for traditional Splunk indexes with .tsidx files. I don't know for sure how other virtual indexes behave here.&lt;/P&gt;

&lt;P&gt;Protip: Tag your questions with Hunk et.al. so people know what you're dealing with.&lt;/P&gt;

&lt;P&gt;Another thought, if your data is bunched together by day - wouldn't it be nice to stick them into one index and specify the timestamp properly for Splunk's &lt;CODE&gt;_time&lt;/CODE&gt; field?&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 17:07:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173449#M49749</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-05-07T17:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: group by index and count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173450#M49750</link>
      <description>&lt;P&gt;|tstats might not work... but a virtual index is an index... meaning you refer to it as index=virtual_index_name. so the last one in my answer should work. &lt;CODE&gt;index=coll* |stats count by index|sort -count&lt;/CODE&gt;  unless you are a) not talking about virtual indexes or b) have not kept to the naming convention... &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:45:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/group-by-index-and-count/m-p/173450#M49750</guid>
      <dc:creator>rsennett_splunk</dc:creator>
      <dc:date>2020-09-28T19:45:56Z</dc:date>
    </item>
  </channel>
</rss>

