<?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 Question about timemodifier in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126121#M34142</link>
    <description>&lt;P&gt;&lt;IMG src="http://answers.splunk.com//storage/needle-in-the-haystack.png" alt="alt text" /&gt;Hi!&lt;/P&gt;

&lt;P&gt;I would like to ask about the timemodifier.&lt;/P&gt;

&lt;P&gt;I have a following search including subsearch,&lt;/P&gt;

&lt;P&gt;index=hoge&lt;BR /&gt;
[ search index=hoge _index_earliesst=-1d@d _index_latest=@d&lt;BR /&gt;
| stats&lt;BR /&gt;
earliest(start) as earliest&lt;BR /&gt;
latest(stop) as latest by field&lt;BR /&gt;
| eval earliest=substr(earliest,5,2) . "/" . substr(earliest,7,2) . "/" . substr(earliest,1,4) . ":" . substr(earliest,9,2) . ":" . substr(earliest,11,2) . ":" . substr(earliest,13,2)&lt;BR /&gt;
| search conditionA&lt;BR /&gt;
| eval latest=substr(latest,5,2) . "/" . substr(latest,7,2) . "/" . substr(latest,1,4) . ":" . substr(latest,9,2) . ":" . substr(latest,11,2) . ":" . substr(latest,13,2)&lt;BR /&gt;
| fields field earliest latest&lt;BR /&gt;
| format "(" "(" "" ")" "OR" ")"&lt;BR /&gt;
]&lt;/P&gt;

&lt;P&gt;My purpose is to search the events that meets the conditionA that were indexed the previous day&lt;BR /&gt;
and pass the earliest and latest time of each field to the main search.&lt;/P&gt;

&lt;P&gt;However, when the number of events should the main search returns are 5000 , it scans more number of events.&lt;/P&gt;

&lt;P&gt;For example,&lt;BR /&gt;
field     earliest            latest&lt;BR /&gt;
fieldA    1/25/2014 00:00     1/25/2014 01:00    3 records exists &lt;BR /&gt;
fieldB    1/25/2014 02:00     1/25/2014 02:00    5 recoreds exists&lt;BR /&gt;
fieldC    1/26/2014 00:00     1/26/2014 01:00&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;my latest event in this record is 1/25/2014 01:50:00&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;if I expect the subsearch to return  (fields="fieldA"  earliest="1/25/2014:00:00" latest="1/25/2014:01:00") OR ( field="fieldB"  earliest="1/25/2014:02:00"  latest="1/25/2014 02:00") , I expect the main search to scan only 8 records, But it seems that it scans the event more than I expect.&lt;/P&gt;

&lt;P&gt;Is the timemodifier not working corrctly if you concatenate with OR's?&lt;/P&gt;

&lt;H1&gt;I have added a screen shot where the scanned events are increasing although the mathing events  are finished.&lt;/H1&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Yu&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 15:43:27 GMT</pubDate>
    <dc:creator>yuwtennis</dc:creator>
    <dc:date>2020-09-28T15:43:27Z</dc:date>
    <item>
      <title>Question about timemodifier</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126121#M34142</link>
      <description>&lt;P&gt;&lt;IMG src="http://answers.splunk.com//storage/needle-in-the-haystack.png" alt="alt text" /&gt;Hi!&lt;/P&gt;

&lt;P&gt;I would like to ask about the timemodifier.&lt;/P&gt;

&lt;P&gt;I have a following search including subsearch,&lt;/P&gt;

&lt;P&gt;index=hoge&lt;BR /&gt;
[ search index=hoge _index_earliesst=-1d@d _index_latest=@d&lt;BR /&gt;
| stats&lt;BR /&gt;
earliest(start) as earliest&lt;BR /&gt;
latest(stop) as latest by field&lt;BR /&gt;
| eval earliest=substr(earliest,5,2) . "/" . substr(earliest,7,2) . "/" . substr(earliest,1,4) . ":" . substr(earliest,9,2) . ":" . substr(earliest,11,2) . ":" . substr(earliest,13,2)&lt;BR /&gt;
| search conditionA&lt;BR /&gt;
| eval latest=substr(latest,5,2) . "/" . substr(latest,7,2) . "/" . substr(latest,1,4) . ":" . substr(latest,9,2) . ":" . substr(latest,11,2) . ":" . substr(latest,13,2)&lt;BR /&gt;
| fields field earliest latest&lt;BR /&gt;
| format "(" "(" "" ")" "OR" ")"&lt;BR /&gt;
]&lt;/P&gt;

&lt;P&gt;My purpose is to search the events that meets the conditionA that were indexed the previous day&lt;BR /&gt;
and pass the earliest and latest time of each field to the main search.&lt;/P&gt;

&lt;P&gt;However, when the number of events should the main search returns are 5000 , it scans more number of events.&lt;/P&gt;

&lt;P&gt;For example,&lt;BR /&gt;
field     earliest            latest&lt;BR /&gt;
fieldA    1/25/2014 00:00     1/25/2014 01:00    3 records exists &lt;BR /&gt;
fieldB    1/25/2014 02:00     1/25/2014 02:00    5 recoreds exists&lt;BR /&gt;
fieldC    1/26/2014 00:00     1/26/2014 01:00&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;my latest event in this record is 1/25/2014 01:50:00&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;if I expect the subsearch to return  (fields="fieldA"  earliest="1/25/2014:00:00" latest="1/25/2014:01:00") OR ( field="fieldB"  earliest="1/25/2014:02:00"  latest="1/25/2014 02:00") , I expect the main search to scan only 8 records, But it seems that it scans the event more than I expect.&lt;/P&gt;

&lt;P&gt;Is the timemodifier not working corrctly if you concatenate with OR's?&lt;/P&gt;

&lt;H1&gt;I have added a screen shot where the scanned events are increasing although the mathing events  are finished.&lt;/H1&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Yu&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:43:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126121#M34142</guid>
      <dc:creator>yuwtennis</dc:creator>
      <dc:date>2020-09-28T15:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: Question about timemodifier</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126122#M34143</link>
      <description>&lt;P&gt;Does the subsearch return what you expected? (Check search inspector)&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2014 14:14:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126122#M34143</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-01-26T14:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Question about timemodifier</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126123#M34144</link>
      <description>&lt;P&gt;Hello martin.&lt;/P&gt;

&lt;P&gt;Yes. The subsearch returns the set of &lt;BR /&gt;
field&lt;BR /&gt;
earliest time in relative time format&lt;BR /&gt;
latest time in relative time format&lt;/P&gt;

&lt;P&gt;format command is working fine.&lt;/P&gt;

&lt;P&gt;It seems that the time modifier is not working as expected in each AND boolean expression. Maybe putting to much time modifier confuses the search...&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2014 14:20:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126123#M34144</guid>
      <dc:creator>yuwtennis</dc:creator>
      <dc:date>2014-01-26T14:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Question about timemodifier</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126124#M34145</link>
      <description>&lt;P&gt;Good, then I don't need to think about that &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Are you basically trying to do this: "Run a subsearch, get a bunch of results, use each result to build a timerange and possibly further filters, and run a search off that"?&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2014 14:24:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126124#M34145</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-01-26T14:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Question about timemodifier</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126125#M34146</link>
      <description>&lt;P&gt;Yes.&lt;/P&gt;

&lt;P&gt;So it will be like,&lt;/P&gt;

&lt;P&gt;(field=hoge1  earliest=xxxx latest=xxxx) OR (field=hoge2  earliest=xxxx latest=xxxx) OR ..... and so on.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2014 14:29:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126125#M34146</guid>
      <dc:creator>yuwtennis</dc:creator>
      <dc:date>2014-01-26T14:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Question about timemodifier</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126126#M34147</link>
      <description>&lt;P&gt;Right - based on your comments, you're probably looking for the &lt;CODE&gt;map&lt;/CODE&gt; command. Consider these two simple searches:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal (earliest=-30d@d latest=-29d@d) OR (earliest=@d latest=now) | bin _time span=1d | stats count by _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That's roughly what you're doing now, tell the search to OR two timeranges... and as you observed, this scans the events in between rather than skipping to the past instantaneously. On my PC, this takes about four seconds.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval times="-30d@d|-29d@d,@d|now" | makemv delim="," times | mvexpand times | makemv delim="|" times | eval starttime=mvindex(times,0) | eval endtime=mvindex(times,1) | map search="search index=_internal earliest=$starttime$ latest=$endtime$ | bin _time span=1d | stats count by _time"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This achieves the same thing, but in a different way. The first bit before &lt;CODE&gt;map&lt;/CODE&gt; creates two events with fields &lt;CODE&gt;starttime&lt;/CODE&gt; and &lt;CODE&gt;endtime&lt;/CODE&gt;, which are used by &lt;CODE&gt;map&lt;/CODE&gt; to run two searches based on those timeranges. The result is the same as in the earlier search, but my PC only takes about one second.&lt;/P&gt;

&lt;P&gt;This should be applicable to your problem, run the current subsearch first and pass into &lt;CODE&gt;map&lt;/CODE&gt; the earliest/latest times as well as the condition.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2014 14:38:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126126#M34147</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-01-26T14:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Question about timemodifier</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126127#M34148</link>
      <description>&lt;P&gt;Thanks martin!&lt;/P&gt;

&lt;P&gt;I have to do some studying with this though. By the way would this work with about thousand set of following conditions( all concatenated with OR)?&lt;/P&gt;

&lt;P&gt;(field=hoge1  earliest=xxxx latest=xxxx)&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2014 14:42:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126127#M34148</guid>
      <dc:creator>yuwtennis</dc:creator>
      <dc:date>2014-01-26T14:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: Question about timemodifier</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126128#M34149</link>
      <description>&lt;P&gt;Not quite sure about a thousand... &lt;CODE&gt;map&lt;/CODE&gt; will run a search for each event it's given, so it would run a thousand searches. By default it stops after ten, so running a thousand may or may not break things. Just give it a shot...&lt;/P&gt;

&lt;P&gt;While you're studying &lt;CODE&gt;map&lt;/CODE&gt;, take a look at &lt;CODE&gt;localize&lt;/CODE&gt; - maybe that could simplify your subsearch for building the timeranges.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jan 2014 14:50:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Question-about-timemodifier/m-p/126128#M34149</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-01-26T14:50:18Z</dc:date>
    </item>
  </channel>
</rss>

