<?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 Search using Stats, String Dates, Counts and Sorting in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Search-using-Stats-String-Dates-Counts-and-Sorting/m-p/24648#M4569</link>
    <description>&lt;P&gt;What I am trying to do is to get a listing of the last 7 days (that logs were entered - not necessarily the last 7 calendar days) and how many completed requests the logs have seen during those days.&lt;/P&gt;

&lt;P&gt;Here is the query I am using:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
  &lt;P&gt;sourcetype="server_log" complete* |
  convert timeformat="%m-%d"
  ctime(_time) as compact_date | stats
  dc(requestid) as "NumRequests" by
  compact_date | rename compact_date as
  RequestDate | tail 7&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;The problem I am seeing is that the compact_date values are not sorted correctly. I am assuming this is because they are strings. &lt;/P&gt;

&lt;P&gt;How can I sort the days correctly?&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jan 2011 00:12:58 GMT</pubDate>
    <dc:creator>htkhtk</dc:creator>
    <dc:date>2011-01-12T00:12:58Z</dc:date>
    <item>
      <title>Search using Stats, String Dates, Counts and Sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-using-Stats-String-Dates-Counts-and-Sorting/m-p/24648#M4569</link>
      <description>&lt;P&gt;What I am trying to do is to get a listing of the last 7 days (that logs were entered - not necessarily the last 7 calendar days) and how many completed requests the logs have seen during those days.&lt;/P&gt;

&lt;P&gt;Here is the query I am using:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
  &lt;P&gt;sourcetype="server_log" complete* |
  convert timeformat="%m-%d"
  ctime(_time) as compact_date | stats
  dc(requestid) as "NumRequests" by
  compact_date | rename compact_date as
  RequestDate | tail 7&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;The problem I am seeing is that the compact_date values are not sorted correctly. I am assuming this is because they are strings. &lt;/P&gt;

&lt;P&gt;How can I sort the days correctly?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2011 00:12:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-using-Stats-String-Dates-Counts-and-Sorting/m-p/24648#M4569</guid>
      <dc:creator>htkhtk</dc:creator>
      <dc:date>2011-01-12T00:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: Search using Stats, String Dates, Counts and Sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-using-Stats-String-Dates-Counts-and-Sorting/m-p/24649#M4570</link>
      <description>&lt;P&gt;I'd recommend binning the dates by their UTC time representation rather than by convert. You could use either timechart or bin+stats to acheive this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="server_log" complete* earliest=-7d@d latest=@d
| timechart span=1d dc(requestid) as NumRequests
| convert timeformat="%m-%d" ctime(_time) as compact_date
| table compact_date NumRequests
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="server_log" complete* earliest=-7d@d latest=@d
| bin span=1d _time
| stats dc(requestid) as NumRequests by _time
| convert timeformat="%m-%d" ctime(_time) as compact_date
| table compact_date NumRequests
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jan 2011 00:26:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-using-Stats-String-Dates-Counts-and-Sorting/m-p/24649#M4570</guid>
      <dc:creator>Stephen_Sorkin</dc:creator>
      <dc:date>2011-01-12T00:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Search using Stats, String Dates, Counts and Sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-using-Stats-String-Dates-Counts-and-Sorting/m-p/24650#M4571</link>
      <description>&lt;P&gt;I wrote this question wrong.. I don't need the latest 7 days. I need the last 7 days that logs were written. So for example, it could be 11-27, 11-28, 12-02, 01-03&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2011 00:35:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-using-Stats-String-Dates-Counts-and-Sorting/m-p/24650#M4571</guid>
      <dc:creator>htkhtk</dc:creator>
      <dc:date>2011-01-12T00:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: Search using Stats, String Dates, Counts and Sorting</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-using-Stats-String-Dates-Counts-and-Sorting/m-p/24651#M4572</link>
      <description>&lt;P&gt;This helped me solve my problem though! I didn't know about bin and span.  See this:&lt;/P&gt;

&lt;P&gt;sourcetype="server_log" complete* | bin span=1d _time | dedup requestid | stats count by _time | sort _time desc&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2011 00:38:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-using-Stats-String-Dates-Counts-and-Sorting/m-p/24651#M4572</guid>
      <dc:creator>htkhtk</dc:creator>
      <dc:date>2011-01-12T00:38:46Z</dc:date>
    </item>
  </channel>
</rss>

