<?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 query help ! in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/stats-query-help/m-p/660710#M228108</link>
    <description>&lt;P&gt;Rather than &lt;FONT face="courier new,courier"&gt;head 1,&lt;/FONT&gt; which returns the first of all results, try &lt;FONT face="courier new,courier"&gt;dedup _time&lt;/FONT&gt;, which will return the first result from each hour (because of the &lt;FONT face="courier new,courier"&gt;bucket&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;sort&lt;/FONT&gt; commands).&lt;/P&gt;</description>
    <pubDate>Fri, 13 Oct 2023 18:10:47 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2023-10-13T18:10:47Z</dc:date>
    <item>
      <title>stats query help !</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-query-help/m-p/660704#M228104</link>
      <description>&lt;P&gt;Hello,&amp;nbsp; I am searching to get results for each hour&amp;nbsp; top 1 max URL hits.&amp;nbsp; Iam using the below search but not getting results for each hour.&lt;/P&gt;&lt;P&gt;index=*&amp;nbsp; | fields Request_URL _time&lt;BR /&gt;| stats count as hits by Request_URL _time |bucket span=1h _time&lt;BR /&gt;| sort by hits desc&lt;BR /&gt;| head 1&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2023 17:36:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-query-help/m-p/660704#M228104</guid>
      <dc:creator>kc_prane</dc:creator>
      <dc:date>2023-10-13T17:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: stats query help !</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-query-help/m-p/660710#M228108</link>
      <description>&lt;P&gt;Rather than &lt;FONT face="courier new,courier"&gt;head 1,&lt;/FONT&gt; which returns the first of all results, try &lt;FONT face="courier new,courier"&gt;dedup _time&lt;/FONT&gt;, which will return the first result from each hour (because of the &lt;FONT face="courier new,courier"&gt;bucket&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;sort&lt;/FONT&gt; commands).&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2023 18:10:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-query-help/m-p/660710#M228108</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-10-13T18:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: stats query help !</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-query-help/m-p/660765#M228135</link>
      <description>&lt;P&gt;Aside from mistaken use of head as&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp;points out, what is the reason to perform stats on _time before bucketing if your goal is to find maximum &lt;EM&gt;per hour&lt;/EM&gt;?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=*
| bucket _time span=1h
| stats count by _time Request_URL
| sort - count
| dedup _time
| sort _time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Oct 2023 06:50:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-query-help/m-p/660765#M228135</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-10-14T06:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: stats query help !</title>
      <link>https://community.splunk.com/t5/Splunk-Search/stats-query-help/m-p/660768#M228137</link>
      <description>&lt;P&gt;1. index=* is something that is very rarely a good idea. Be as specific about your search as you can to use resources effectively&lt;/P&gt;&lt;P&gt;2. It makes no sense to stats by time and only afterwards splitting into time-based buckets. For such case you should either bin first and then stats by _time or simply use timechart with a proper span.&lt;/P&gt;&lt;P&gt;3. As was already pointed out, head is not tbe way to go. The alternative to using dedup could be using stats first or last&lt;/P&gt;&lt;P&gt;So your final search could look like this&lt;/P&gt;&lt;PRE&gt;index=&amp;lt;be_specific_here&amp;gt;&lt;BR /&gt;| bin span=1h _time&lt;BR /&gt;| stats count by Request_URL _time&lt;BR /&gt;| sort _time count&lt;BR /&gt;| stats last(*) as * by _time&lt;/PRE&gt;&lt;P&gt;As an exercise you could try to solve the same problem using another approach - adding stats with eventstats and filtering with where&lt;/P&gt;</description>
      <pubDate>Sat, 14 Oct 2023 07:49:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/stats-query-help/m-p/660768#M228137</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-10-14T07:49:10Z</dc:date>
    </item>
  </channel>
</rss>

