<?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 write a search to only return data from a set time range (8:00 to 16:00) each day? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237941#M70704</link>
    <description>&lt;P&gt;@aljohnson Since you work for Splunk, I'm going to ask you if this approach is more efficient than running a bunch of appends with the desired time ranges, and if so, why?&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jan 2016 21:03:01 GMT</pubDate>
    <dc:creator>masonmorales</dc:creator>
    <dc:date>2016-01-20T21:03:01Z</dc:date>
    <item>
      <title>How to write a search to only return data from a set time range (8:00 to 16:00) each day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237939#M70702</link>
      <description>&lt;P&gt;Using &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| bucket span=1d _time
| stats count by _time 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and set custom time &lt;CODE&gt;@d+8h&lt;/CODE&gt; to get TODAY'S data from 8AM onwards until &lt;CODE&gt;@d+16h&lt;/CODE&gt; whenever I run the report.&lt;/P&gt;

&lt;P&gt;However, I want to create a list of the results for EACH of the last 7 days that only includes data from the day 08:00 up until 16:00.&lt;/P&gt;

&lt;P&gt;I tried to do via the custom time:&lt;BR /&gt;
Start&lt;BR /&gt;
&lt;CODE&gt;-7d@d+8h&lt;/CODE&gt;&lt;BR /&gt;
Latest&lt;BR /&gt;
&lt;CODE&gt;@d+16h&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;but this ends up including all the data from 24 hours between those two date / time ranges&lt;/P&gt;

&lt;P&gt;I just want 08:00 to 16:00 each day &lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 12:53:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237939#M70702</guid>
      <dc:creator>TCK101</dc:creator>
      <dc:date>2016-01-20T12:53:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only return data from a set time range (8:00 to 16:00) each day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237940#M70703</link>
      <description>&lt;P&gt;Add &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval date_hour = strftime(_time, "%H")
| search date_hour&amp;gt;8 date_hour&amp;lt;16
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to your existing search and you should be good to go.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 17:19:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237940#M70703</guid>
      <dc:creator>aljohnson_splun</dc:creator>
      <dc:date>2016-01-20T17:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only return data from a set time range (8:00 to 16:00) each day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237941#M70704</link>
      <description>&lt;P&gt;@aljohnson Since you work for Splunk, I'm going to ask you if this approach is more efficient than running a bunch of appends with the desired time ranges, and if so, why?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 21:03:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237941#M70704</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2016-01-20T21:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only return data from a set time range (8:00 to 16:00) each day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237942#M70705</link>
      <description>&lt;P&gt;In all but the most extreme cases, running a single query with more arguments is going to be faster than running multiple queries and using append, just because of the time to set up each query. Append also has a time limit, as all sub-searches do.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 17:50:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237942#M70705</guid>
      <dc:creator>vbumgarner</dc:creator>
      <dc:date>2016-01-21T17:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only return data from a set time range (8:00 to 16:00) each day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237943#M70706</link>
      <description>&lt;P&gt;date_hour is an indexed field, so you can do this in your original query.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;originial search date_hour&amp;gt;8 date_hour&amp;lt;16&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;The goal is to pull fewer events off the disk, and use the index wherever possible. If you can do it in the base query, then you can also use it as the query for an accelerated data model, which I'm guessing you'll want for your use case. Incidentally, I assumed that spelling each hour out with a bunch OR statements would have been more efficient, but it doesn't seem to make any difference. I think that's an improvement in recent years.&lt;/P&gt;

&lt;P&gt;Is the reason for the timeframe to find "business hours"? The date_hour is UTC, so is not going to honor Daylight savings. Pad accordingly.&lt;/P&gt;

&lt;P&gt;This would be a great use for an eventtype, then you can simply add to any query &lt;CODE&gt;eventtype=businesshours&lt;/CODE&gt;. An eventtype does introduce some added load, since it is calculated any time you run a query against the events that the eventtype is configured to apply to, so for minimal load, use a macro. An eventtype is handy in other ways, of course, but it does introduce load.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 18:01:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237943#M70706</guid>
      <dc:creator>vbumgarner</dc:creator>
      <dc:date>2016-01-21T18:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only return data from a set time range (8:00 to 16:00) each day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237944#M70707</link>
      <description>&lt;P&gt;the problem with using &lt;CODE&gt;date_hour&lt;/CODE&gt; is that they don't reflect timezone changes - see this answer &lt;A href="https://answers.splunk.com/answers/99451/variance-betweeen-time-and-date-fields.html"&gt;here&lt;/A&gt; for a detailed response.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 19:30:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237944#M70707</guid>
      <dc:creator>aljohnson_splun</dc:creator>
      <dc:date>2016-01-21T19:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only return data from a set time range (8:00 to 16:00) each day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237945#M70708</link>
      <description>&lt;P&gt;vbmgarner nailed it. basically, subsearches have limitations. I'm sure you've seen people asking regularly how to &lt;STRONG&gt;avoid&lt;/STRONG&gt; subsearches for that exact reason. If possible, its (generally) better to avoid them if possible. In terms of whether or not its actually more performant, I'll let someone else do a test. The search job inspector will let you know if the gain is worth it or not.&lt;/P&gt;

&lt;P&gt;Check out the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.2/Search/Aboutsubsearches#Subsearch_performance"&gt;docs here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 20:17:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237945#M70708</guid>
      <dc:creator>aljohnson_splun</dc:creator>
      <dc:date>2016-01-21T20:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only return data from a set time range (8:00 to 16:00) each day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237946#M70709</link>
      <description>&lt;P&gt;True, but you should always strive to pull less off the disk. The best answer is probably the combination -- use date_hour to get the hours that are possible, given DST, then use the search filter to throw away the one hour that isn't useful.&lt;/P&gt;

&lt;P&gt;If using a data model, you could set a couple of fields to subsequently filter on. &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;dst_hour=strftime(_time, "%H")&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;business_hours=if(dst_hour&amp;gt;8 and dst_hour&amp;lt;16, 1, 0)&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 21:13:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237946#M70709</guid>
      <dc:creator>vbumgarner</dc:creator>
      <dc:date>2016-01-21T21:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only return data from a set time range (8:00 to 16:00) each day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237947#M70710</link>
      <description>&lt;P&gt;Or I suppose define an eval field, and use that in the eventtype or datamodel query? I haven't used eval fields anywhere...&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 21:14:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237947#M70710</guid>
      <dc:creator>vbumgarner</dc:creator>
      <dc:date>2016-01-21T21:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to only return data from a set time range (8:00 to 16:00) each day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237948#M70711</link>
      <description>&lt;P&gt;Oh, now I read the post you linked to. I didn't realize how limited those fields actually are. Okay, so they should be used with a bucket full of caveats. Too bad.&lt;/P&gt;

&lt;P&gt;So, the only supportable way to make this particularly efficient, if this data is going to be used a lot, is to make a data model, make an eval field that determines if the date is in scope, and then accelerate that data model. That's your only hope to make this efficient.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 21:27:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-only-return-data-from-a-set-time-range/m-p/237948#M70711</guid>
      <dc:creator>vbumgarner</dc:creator>
      <dc:date>2016-01-21T21:27:36Z</dc:date>
    </item>
  </channel>
</rss>

