<?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 check if an index exists efficiently? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438041#M172539</link>
    <description>&lt;P&gt;While tstats is much faster than a normal search (doing index=... | stats), and tstats is time aware which may suit your needs. However that said, tstats is not as fast as the eventcount command or the REST queries that you could be able to use.&lt;/P&gt;

&lt;P&gt;As per my post I prefer eventcount if you just want a list of available indexes, keep in mind the eventcount command is not time aware as per the documentation:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Specifying a time range has no effect on the results returned by the eventcount command. All of the events on the indexes you specify are counted. 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the goal is to find information that is time-based then use tstats as per MuS's post.&lt;/P&gt;</description>
    <pubDate>Wed, 13 Mar 2019 11:43:40 GMT</pubDate>
    <dc:creator>gjanders</dc:creator>
    <dc:date>2019-03-13T11:43:40Z</dc:date>
    <item>
      <title>How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438034#M172532</link>
      <description>&lt;P&gt;In elasticsearch one would do HEAD [index_name] and check if an index exists efficiently. Is it possible to do something similar in Splunk? &lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 10:28:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438034#M172532</guid>
      <dc:creator>dapitis</dc:creator>
      <dc:date>2019-03-12T10:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438035#M172533</link>
      <description>&lt;P&gt;You could run  a rest search &lt;CODE&gt;|rest /services/data/indexes | fields title | rename title AS index&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 12:10:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438035#M172533</guid>
      <dc:creator>lakshman239</dc:creator>
      <dc:date>2019-03-12T12:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438036#M172534</link>
      <description>&lt;P&gt;This will return me all the indices and not a kind of a binary response if a specific index exists or not (for the elasticsearch case one could check the status code of the response).&lt;/P&gt;

&lt;P&gt;A possible solution seems to be this one but I am not sure how efficient it is:&lt;BR /&gt;
| eventcount summarize=false index=[index_name] | dedup index | fields index&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 13:33:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438036#M172534</guid>
      <dc:creator>dapitis</dc:creator>
      <dc:date>2019-03-12T13:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438037#M172535</link>
      <description>&lt;P&gt;you could just add &lt;CODE&gt;|rest /services/data/indexes | fields title | rename title AS index | search index=yourindexname&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 14:40:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438037#M172535</guid>
      <dc:creator>lakshman239</dc:creator>
      <dc:date>2019-03-12T14:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438038#M172536</link>
      <description>&lt;P&gt;I have used:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventcount summarize=false index=* index=_*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And found it to be very efficient, it does not require the ability to run REST queries on the indexers so 1 less capability the user needs.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 22:06:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438038#M172536</guid>
      <dc:creator>gjanders</dc:creator>
      <dc:date>2019-03-12T22:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438039#M172537</link>
      <description>&lt;P&gt;You can also just head to the GUI (flash timeline search) to use the &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.4/SearchReference/Typeahead"&gt;&lt;CODE&gt;typeahead&lt;/CODE&gt;&lt;/A&gt; feature for dummyproof results. (e.g. type index=p and you get all the indexes that start with a &lt;CODE&gt;p&lt;/CODE&gt; in which your particular RBAC has access for)&lt;/P&gt;

&lt;P&gt;BUT CHECK THIS OUT! ... That doc I linked above shows &lt;CODE&gt;typeahead&lt;/CODE&gt; being used as a search/api/ish feature that you can utilize for fast recovery of knowledge objects! TIL.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| typeahead prefix=source count=10 index=_internal
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Mar 2019 02:29:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438039#M172537</guid>
      <dc:creator>jtrujillo</dc:creator>
      <dc:date>2019-03-13T02:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438040#M172538</link>
      <description>&lt;P&gt;Hi dapitis,&lt;/P&gt;

&lt;P&gt;the most efficient way in Splunk is to use &lt;CODE&gt;tstats&lt;/CODE&gt; like this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | tstats count WHERE index=&amp;lt;PlaceYourIndexNamehere&amp;gt; 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will not search any &lt;CODE&gt;_raw&lt;/CODE&gt; data and therefore it is very, very fast &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;BR /&gt;
Don't forget to set the correct time range if you run the search.&lt;/P&gt;

&lt;P&gt;hope that helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 02:50:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438040#M172538</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2019-03-13T02:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438041#M172539</link>
      <description>&lt;P&gt;While tstats is much faster than a normal search (doing index=... | stats), and tstats is time aware which may suit your needs. However that said, tstats is not as fast as the eventcount command or the REST queries that you could be able to use.&lt;/P&gt;

&lt;P&gt;As per my post I prefer eventcount if you just want a list of available indexes, keep in mind the eventcount command is not time aware as per the documentation:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Specifying a time range has no effect on the results returned by the eventcount command. All of the events on the indexes you specify are counted. 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the goal is to find information that is time-based then use tstats as per MuS's post.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 11:43:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438041#M172539</guid>
      <dc:creator>gjanders</dc:creator>
      <dc:date>2019-03-13T11:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438042#M172540</link>
      <description>&lt;P&gt;Be aware that all &lt;CODE&gt;tstats&lt;/CODE&gt; or &lt;CODE&gt;eventcount&lt;/CODE&gt; or similar searches will return a result even if the index is not created at all. The only way to really tell if an index is there would be calling the REST interface.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rest /services/data/indexes | stats count(eval(title=="yourindex")) as exists
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This search will return &lt;CODE&gt;0&lt;/CODE&gt; if your index does not exist, and &lt;CODE&gt;1&lt;/CODE&gt; if it exists - even if it has no events.&lt;/P&gt;

&lt;P&gt;If you save this search as a eval macro and pass the index name as a variable you can include this in any search if needed.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 12:03:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438042#M172540</guid>
      <dc:creator>DMohn</dc:creator>
      <dc:date>2019-03-13T12:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438043#M172541</link>
      <description>&lt;P&gt;Be aware that this search will return a valid result even if the index is not existant at all. I guess this is not what was asked.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 12:04:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438043#M172541</guid>
      <dc:creator>DMohn</dc:creator>
      <dc:date>2019-03-13T12:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438044#M172542</link>
      <description>&lt;P&gt;Not sure what version you are running but on Splunk 7.1.4 this SPL&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index=DieserIndexExistiertNicht by index
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;returns &lt;CODE&gt;No results found.&lt;/CODE&gt; &lt;BR /&gt;
Also this one &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index=DieserIndexExistiertNicht
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;returns a count of &lt;CODE&gt;0&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;One might claim this a valid result ? IMHO it is not &lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 19:03:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438044#M172542</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2019-03-13T19:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438045#M172543</link>
      <description>&lt;P&gt;And yet another &lt;CODE&gt;be aware&lt;/CODE&gt; post &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;This will only work if you either:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;run it on the indexer itself and it will only return the indexes this indexer has configured&lt;/LI&gt;
&lt;LI&gt;run it on an instance that has indexers configured as search peer and if you have the correct permissions granted then it will show all configured indexes - otherwise you will get this error &lt;CODE&gt;Restricting results of the "rest" operator to the local instance because you do not have the "dispatch_rest_to_indexers" capability.&lt;/CODE&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;All of the SPL commands listed in all the posts are valid and useful, all of them have their limitations and all of them can be used to achieve the same, if you keep all the &lt;CODE&gt;be awares&lt;/CODE&gt; in mind &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 19:17:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438045#M172543</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2019-03-13T19:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438046#M172544</link>
      <description>&lt;P&gt;An yes, of course you are right &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;The famous world of Splunk, with all its culprits and pitfalls...&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 20:10:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438046#M172544</guid>
      <dc:creator>DMohn</dc:creator>
      <dc:date>2019-03-13T20:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if an index exists efficiently?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438047#M172545</link>
      <description>&lt;P&gt;... and doesn't work on metric indexes&lt;/P&gt;

&lt;P&gt;but thx - worked for event idx's&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 23:16:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-check-if-an-index-exists-efficiently/m-p/438047#M172545</guid>
      <dc:creator>Esky73</dc:creator>
      <dc:date>2020-03-19T23:16:53Z</dc:date>
    </item>
  </channel>
</rss>

