<?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: stats command not working as expected in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434712#M170646</link>
    <description>&lt;P&gt;wild guess here is that you want to add &lt;CODE&gt;global=false&lt;/CODE&gt; to your &lt;CODE&gt;streamstats&lt;/CODE&gt; as you are splitting by something&lt;/P&gt;

&lt;P&gt;try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=ssys_internal_pj AND sourcetype=*log* 
    | streamstats current=f global=false last(_time) as last_time last(source) as last_source by SerialNumber 
    | eval gap = last_time - _time 
    | where gap &amp;gt; 14400 
    | convert timeformat="%Y-%m-%d %H:%M:%S" ctime(last_time) as last_time 
    | table SerialNumber _time last_time last_source source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;read more here:&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.0/SearchReference/Streamstats"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.0/SearchReference/Streamstats&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jun 2019 17:32:44 GMT</pubDate>
    <dc:creator>adonio</dc:creator>
    <dc:date>2019-06-19T17:32:44Z</dc:date>
    <item>
      <title>stats command not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434707#M170641</link>
      <description>&lt;P&gt;hello&lt;BR /&gt;
i have this query that calculated gaps between events.&lt;BR /&gt;
im trying to get the source file of the events that was captured but im getting the wrong results.&lt;BR /&gt;
this is my query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=ssys_internal_pj AND sourcetype=*log*
| streamstats current=f last(_time) as last_time last(source) as last_source  by SerialNumber    
| eval gap = last_time - _time | where gap &amp;gt; 14400 | convert timeformat="%Y-%m-%d %H:%M:%S" ctime(last_time) as last_time | table SerialNumber _time last_time  last_source source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the result im getting is the last source file of this SerialNumber not related at all to the _time and last_time that was captured&lt;/P&gt;

&lt;P&gt;how can i get the right sources ?&lt;/P&gt;

&lt;P&gt;also, is there a way to use tstats to make this query run faster? it is very slow&lt;/P&gt;

&lt;P&gt;thanks &lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:00:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434707#M170641</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2020-09-30T01:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: stats command not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434708#M170642</link>
      <description>&lt;P&gt;Hello @sarit_s - Could you please  explain question more clearly or it would be greate if you can give sample results that you are getting and result you are expecting.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 14:16:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434708#M170642</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2019-06-19T14:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: stats command not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434709#M170643</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;
this is an example of the result im getting:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SerialNumber
8500154     
_time   
2019-06-17 12:15:32
last_time
2019-06-17 23:53:20 
    last_source
s3:///2019-06-17T13:07:47.939Z_1.91.0.192_1.92.0.0_31.31.58.12484/SANITIZED_17-06-19-11-32.log  
    source
    s3:///2019-06-17T13:07:47.939Z_1.91.0.192_1.92.0.0_31.31.58.12484/SANITIZED_17-06-19-11-32.log
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;as you can see the source is the same at both source and last_source&lt;BR /&gt;
and neither of them is the right one &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;i want to get the source of the event that was captured at 2019-06-17 12:15:32&lt;BR /&gt;
and the source of the event that was captured at 2019-06-17 23:53:20&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 14:26:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434709#M170643</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-06-19T14:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: stats command not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434710#M170644</link>
      <description>&lt;P&gt;I'm still not sure about your requirement, but I guess you want latest source in that case try removing  &lt;CODE&gt;current=f&lt;/CODE&gt; from your query.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 14:34:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434710#M170644</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2019-06-19T14:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: stats command not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434711#M170645</link>
      <description>&lt;P&gt;this option returning no results at all&lt;/P&gt;

&lt;P&gt;im not looking for latest source&lt;BR /&gt;
i have _time and last _time&lt;BR /&gt;
each one of them coming from event&lt;BR /&gt;
i want to see the source of this event&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 14:44:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434711#M170645</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-06-19T14:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: stats command not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434712#M170646</link>
      <description>&lt;P&gt;wild guess here is that you want to add &lt;CODE&gt;global=false&lt;/CODE&gt; to your &lt;CODE&gt;streamstats&lt;/CODE&gt; as you are splitting by something&lt;/P&gt;

&lt;P&gt;try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=ssys_internal_pj AND sourcetype=*log* 
    | streamstats current=f global=false last(_time) as last_time last(source) as last_source by SerialNumber 
    | eval gap = last_time - _time 
    | where gap &amp;gt; 14400 
    | convert timeformat="%Y-%m-%d %H:%M:%S" ctime(last_time) as last_time 
    | table SerialNumber _time last_time last_source source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;read more here:&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.0/SearchReference/Streamstats"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.0/SearchReference/Streamstats&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;hope it helps&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 17:32:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434712#M170646</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-06-19T17:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: stats command not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434713#M170647</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=ssys_internal_pj AND sourcetype=*log*
 | streamstats current=f window=1 values(_time) as last_time values(source) as last_source  by SerialNumber    
 | eval gap = last_time - _time | where gap &amp;gt; 14400 | convert timeformat="%Y-%m-%d %H:%M:%S" ctime(last_time) as last_time | table SerialNumber _time last_time  last_source source
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jun 2019 19:08:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434713#M170647</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2019-06-19T19:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: stats command not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434714#M170648</link>
      <description>&lt;P&gt;hi&lt;BR /&gt;
thanks for your answer,&lt;BR /&gt;
this option does not return the right results.. &lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 06:11:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434714#M170648</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-06-20T06:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: stats command not working as expected</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434715#M170649</link>
      <description>&lt;P&gt;hi&lt;BR /&gt;
thanks for your answer&lt;BR /&gt;
this is the result im getting&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  last_time 
        2019-06-17 15:22:03



last_source 
s3:///2019-06-02T23:53:43.027Z_1.91.0.192_1.88.0.0_31.30.75.12117/SANITIZED_02-06-19-12-22.log
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;as you can see the last time was 2019-06-17 and the last source was from 02-06-19 which is not correct&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 06:13:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-command-not-working-as-expected/m-p/434715#M170649</guid>
      <dc:creator>sarit_s</dc:creator>
      <dc:date>2019-06-20T06:13:53Z</dc:date>
    </item>
  </channel>
</rss>

