<?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: Need help using Tstats getting count of a string in raw logs in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494174#M194499</link>
    <description>&lt;P&gt;It won't work with tstats, but &lt;CODE&gt;rex&lt;/CODE&gt; and &lt;CODE&gt;mvcount&lt;/CODE&gt; will work.&lt;/P&gt;

&lt;P&gt;For the &lt;CODE&gt;tstats&lt;/CODE&gt; to work, first the string has to follow segmentation rules.&lt;BR /&gt;
Second, you only get a count of the events containing the string as presented in segmentation form.  If the string appears multiple times in an event, you won't see that.&lt;/P&gt;

&lt;P&gt;The best you can get is a count of the number of events containing the string if it follows the segmentation rules or it's contained in an indexed field.  Any string with major segment breakers in it will fail in tstats TERM.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index=foo sourcetype=bar TERM(mySegment) TERM(mySegment2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also, if you ever consider using NOT with &lt;CODE&gt;tstats&lt;/CODE&gt;, you'll also need to consider the effects of the following Splunk bug: &lt;A href="https://answers.splunk.com/answers/787657/not-term-removes-results.html?childToView=787658#answer-787658"&gt;https://answers.splunk.com/answers/787657/not-term-removes-results.html?childToView=787658#answer-787658&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;The better solution is to extract and count each string with &lt;CODE&gt;rex&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;yourIndexName&amp;gt; "yourString"
| rex max_match=0 "(?&amp;lt;yourStringName&amp;gt;yourString)" 
| eval str_cnt = mvcount(yourStringName)
| stats sum(str_cnt) AS "No. of occurrences"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 02 Dec 2019 13:19:25 GMT</pubDate>
    <dc:creator>landen99</dc:creator>
    <dc:date>2019-12-02T13:19:25Z</dc:date>
    <item>
      <title>Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494164#M194489</link>
      <description>&lt;P&gt;I want to show the count of logs where a string appeared &lt;/P&gt;

&lt;P&gt;I have a string and need to know how many times it appears in logs &lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 12:10:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494164#M194489</guid>
      <dc:creator>aamer86</dc:creator>
      <dc:date>2019-11-27T12:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494165#M194490</link>
      <description>&lt;P&gt;@aamer86 if the field/fields containing the &lt;CODE&gt;string&lt;/CODE&gt; you want to count are &lt;BR /&gt;
(1) indexed extracted or &lt;BR /&gt;
(2) has accelerated Data Model created then only you can use the &lt;CODE&gt;tstats&lt;/CODE&gt; command. &lt;/P&gt;

&lt;P&gt;Otherwise you will have to perform regular index search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;yourIndexName&amp;gt; "&amp;lt;yourString&amp;gt;"
| stats count as "No. of occurrences"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please provide more details for the community to assist you better.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 12:24:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494165#M194490</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-11-27T12:24:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494166#M194491</link>
      <description>&lt;P&gt;the string is indexed but i need to get numbers over long period so i want to use tstats but the index is not in any Data Model &lt;/P&gt;

&lt;P&gt;I remember once I saw tstats used with raw but cant remember the context &lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 12:54:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494166#M194491</guid>
      <dc:creator>aamer86</dc:creator>
      <dc:date>2019-11-27T12:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494167#M194492</link>
      <description>&lt;P&gt;if your data has indexed extractions, then you can use tstats as follows&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|tstats count as total where index=&amp;lt;your index&amp;gt; AND &amp;lt;your field&amp;gt;=&amp;lt;your value&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;by default, metadata fields such as host, source, sourcetype, and _time are indexed. unless &lt;CODE&gt;&amp;lt;your field&amp;gt;&lt;/CODE&gt; is defined as an indexed extraction, the tstats won't work. &lt;/P&gt;

&lt;P&gt;The other alternative is to build a datamodel on your data to be able to use tstats. if you have a datamodel defined, your tstats would be like this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count as total from datamodel=&amp;lt; your datamodel name&amp;gt; where nodename=&amp;lt;your node name&amp;gt; AND &amp;lt;your node name&amp;gt;.&amp;lt;your field&amp;gt;=&amp;lt;your value&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you have neither&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;your index&amp;gt; &amp;lt;your field filter&amp;gt;
| stats count as total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Nov 2019 13:15:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494167#M194492</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-11-27T13:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494168#M194493</link>
      <description>&lt;P&gt;Thanks @arjunpkishore5  but this doesnt get me what I want &lt;/P&gt;

&lt;P&gt;So the field is not from the indexed extraction fields i.e. it is not hostname, index, sourcetype or sourse.&lt;/P&gt;

&lt;P&gt;I dont want to create a DataModel &lt;/P&gt;

&lt;P&gt;I want to use tstats as it is faster &lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 13:22:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494168#M194493</guid>
      <dc:creator>aamer86</dc:creator>
      <dc:date>2019-11-27T13:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494169#M194494</link>
      <description>&lt;P&gt;As performant as tstats is, it cannot be used without an indexed field extractions or a datamodel. If you must use tstats, have the fields added to your indexed extractions. This however has performance impact and increased disk usage during indexing. Or, create a datamodel. &lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 15:05:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494169#M194494</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-11-27T15:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494170#M194495</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index="foo" AND sourcetype="bar" AND TERM(SearchStringHere)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Nov 2019 18:00:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494170#M194495</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-11-27T18:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494171#M194496</link>
      <description>&lt;P&gt;This is not exactly true; it can also leverage the &lt;CODE&gt;terms&lt;/CODE&gt; in the &lt;CODE&gt;tsidx&lt;/CODE&gt; file.  See my answer.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 21:41:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494171#M194496</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-11-27T21:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494172#M194497</link>
      <description>&lt;P&gt;Thanks @woodcock &lt;/P&gt;

&lt;P&gt;This is exactly what I was looking for &lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 09:54:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494172#M194497</guid>
      <dc:creator>aamer86</dc:creator>
      <dc:date>2019-11-28T09:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494173#M194498</link>
      <description>&lt;P&gt;It won't work.&lt;BR /&gt;
First, the string has to follow segmentation rules.&lt;BR /&gt;
Second, you only get a count of the events containing the string as presented in segmentation form.  If the string appears multiple times in an event, you won't see that.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 13:14:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494173#M194498</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2019-12-02T13:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494174#M194499</link>
      <description>&lt;P&gt;It won't work with tstats, but &lt;CODE&gt;rex&lt;/CODE&gt; and &lt;CODE&gt;mvcount&lt;/CODE&gt; will work.&lt;/P&gt;

&lt;P&gt;For the &lt;CODE&gt;tstats&lt;/CODE&gt; to work, first the string has to follow segmentation rules.&lt;BR /&gt;
Second, you only get a count of the events containing the string as presented in segmentation form.  If the string appears multiple times in an event, you won't see that.&lt;/P&gt;

&lt;P&gt;The best you can get is a count of the number of events containing the string if it follows the segmentation rules or it's contained in an indexed field.  Any string with major segment breakers in it will fail in tstats TERM.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index=foo sourcetype=bar TERM(mySegment) TERM(mySegment2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also, if you ever consider using NOT with &lt;CODE&gt;tstats&lt;/CODE&gt;, you'll also need to consider the effects of the following Splunk bug: &lt;A href="https://answers.splunk.com/answers/787657/not-term-removes-results.html?childToView=787658#answer-787658"&gt;https://answers.splunk.com/answers/787657/not-term-removes-results.html?childToView=787658#answer-787658&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;The better solution is to extract and count each string with &lt;CODE&gt;rex&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;yourIndexName&amp;gt; "yourString"
| rex max_match=0 "(?&amp;lt;yourStringName&amp;gt;yourString)" 
| eval str_cnt = mvcount(yourStringName)
| stats sum(str_cnt) AS "No. of occurrences"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Dec 2019 13:19:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494174#M194499</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2019-12-02T13:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494175#M194500</link>
      <description>&lt;P&gt;Agreed, it is a somewhat limited solution but it is the best that can be done.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 15:25:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494175#M194500</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-02T15:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494176#M194501</link>
      <description>&lt;P&gt;Thanks @landen99  &lt;/P&gt;

&lt;P&gt;does that mean if im looking for a string like this &lt;/P&gt;

&lt;P&gt;"eventName": "DeleteBucketPolicy &lt;/P&gt;

&lt;P&gt;it wont work due to space and double qoute ?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 15:19:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494176#M194501</guid>
      <dc:creator>aamer86</dc:creator>
      <dc:date>2019-12-30T15:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494177#M194502</link>
      <description>&lt;P&gt;TERM will not work with that explicit string, but you can search for the combination of the two substrings: eventname AND deletebucketpolicy (case insensitive).  The odds of false positive event matches on those two strings surely must be extremely low to non-existent.  A much slower way to do it is just to extract the string with &lt;CODE&gt;rex&lt;/CODE&gt; multiple times and then count the number of extractions (in the event that an event may contain the string more than once and you want to count every instance).&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 17:13:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494177#M194502</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2019-12-30T17:13:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494178#M194503</link>
      <description>&lt;P&gt;Yes, there is no way to use &lt;CODE&gt;TERM&lt;/CODE&gt; with a string with &lt;CODE&gt;double-quotes&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 17:24:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494178#M194503</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-30T17:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need help using Tstats getting count of a string in raw logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494179#M194504</link>
      <description>&lt;P&gt;tstats only counts events, not string occurrences.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 17:27:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-help-using-Tstats-getting-count-of-a-string-in-raw-logs/m-p/494179#M194504</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2019-12-30T17:27:22Z</dc:date>
    </item>
  </channel>
</rss>

