<?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 can I create a subsearch with multiple time ranges? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375092#M110222</link>
    <description>&lt;P&gt;Unfortunately that doesn't do the trick. But I'm definitely going to start using multisearch, that seems like a lot simpler solution than append. &lt;/P&gt;

&lt;P&gt;Still, when I format that string into a subsearch, it pulls the times outside of each of the individual searches. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[| gentimes start=-3
| eval earliest=starttime
| eval latest=starttime+30
| eval search="*"
| fields search earliest latest
| format "| multisearch [search" "" "" "" "] [search" "]"
| rex field=search mode=sed "s/\"//g"
| rex field=search mode=sed "s/'/\"/g"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;leads to this error: &lt;BR /&gt;
Error in 'multisearch' command: Invalid argument: '_time&amp;gt;=1522022400.000'&lt;/P&gt;

&lt;P&gt;And this is from logs for what it's actually searching in the subsearch: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;litsearch | multisearch [search ] [search ] [search ] _time&amp;gt;=1522022400.000 _time&amp;lt;1522022430.000 
| fields keepcolorder=t "*" "_bkt" "_cd" "_si" "host" "index" "linecount" "source" "sourcetype" "splunk_server" 
| remotetl nb=300 et=1522022400.000000 lt=1522022430.000000 remove=true max_count=1000 max_prefetch=100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So that _time&amp;gt;=1522022400.000 _time&amp;lt;1522022430.000 bit is messing up the subsearch. &lt;/P&gt;</description>
    <pubDate>Tue, 27 Mar 2018 02:53:40 GMT</pubDate>
    <dc:creator>aguthrie1190</dc:creator>
    <dc:date>2018-03-27T02:53:40Z</dc:date>
    <item>
      <title>How can I create a subsearch with multiple time ranges?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375082#M110212</link>
      <description>&lt;P&gt;I'm trying to write a subsearch that searches multiple sections of time. What I have works until I wrap it in brackets for the subsearch. Here is what I have so far: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-3
| eval earliest=starttime
| eval latest=starttime+20
| eval search="My search here"
| fields search earliest latest
| format "index=notAnIndex earliest=-1m | append [search" "" "" "" "] | append [search" "]"
| rex field=search mode=sed "s/\"//g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This returns this search string:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=notAnIndex earliest=-1m 
| append [search earliest=1521504000 latest=1521504020 My search here ] 
| append [search earliest=1521590400 latest=1521590420 My search here ] 
| append [search earliest=1521676800 latest=1521676820 My search here ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have to use append instead of OR's because using OR will search the whole time frame between the earliest and latest time specified, which defeats the purpose of this. If I copy and paste the returned search string into a new search, it works great. If I wrap the original search in brackets, I get this error: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'append' command: The last argument must be a subsearch.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Looking through the job inspector, I can see that my earliest and latest times are being stripped out of the search. And then the error is probably from that _time that is tacked on to the end of the subsearch &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;litsearch index=notAnIndex 
| append [search My search here ] 
| append [search My search here ] 
| append [search My search here ] _time&amp;gt;=1521676800.000 _time&amp;lt;1521676820.000 
| fields keepcolorder=t "*" "_bkt" "_cd" "_si" "host" "index" "linecount" "source" "sourcetype" "splunk_server" 
| remotetl nb=300 et=1521676800.000000 lt=1521676820.000000 remove=true max_count=1000 max_prefetch=100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This seems like a bug, but maybe I just don't understand how the subsearch is supposed to work here. Has anyone found a way to make something like this work?&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 03:26:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375082#M110212</guid>
      <dc:creator>aguthrie1190</dc:creator>
      <dc:date>2018-03-23T03:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a subsearch with multiple time ranges?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375083#M110213</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Can you try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| append [search index=anyindex earliest=1521504000 latest=1521504020 | remaining search ] 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Mar 2018 06:03:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375083#M110213</guid>
      <dc:creator>p_gurav</dc:creator>
      <dc:date>2018-03-23T06:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a subsearch with multiple time ranges?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375084#M110214</link>
      <description>&lt;P&gt;Can you expand a little? I don't know where you meant for me to put that. I added it to the beginning of the format section, so that the subsearch would output the append at the beginning, but unfortunately that did not work. &lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 12:13:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375084#M110214</guid>
      <dc:creator>aguthrie1190</dc:creator>
      <dc:date>2018-03-23T12:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a subsearch with multiple time ranges?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375085#M110215</link>
      <description>&lt;P&gt;Can you tell e what search you are running in append command, so i can explain it better.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 12:35:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375085#M110215</guid>
      <dc:creator>p_gurav</dc:creator>
      <dc:date>2018-03-23T12:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a subsearch with multiple time ranges?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375086#M110216</link>
      <description>&lt;P&gt;You can replace "My search here" with the search "*" to see the behavior. I'm using "call_start" as that's a frequently seen log in my system. &lt;/P&gt;

&lt;P&gt;The idea is to take the output of gentimes, get a lot of 30 second slices going back many days, and then append each of those 30 second slices together to get a picture of what happens historically.&lt;/P&gt;

&lt;P&gt;I'm using Splunk 6.4.0 in production, I tried this in a lab in 7, and it didn't error out with the same error message, but the same behavior was seen in the job inspector. &lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 12:41:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375086#M110216</guid>
      <dc:creator>aguthrie1190</dc:creator>
      <dc:date>2018-03-23T12:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a subsearch with multiple time ranges?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375087#M110217</link>
      <description>&lt;P&gt;Agreed, I think the actual search  you are running would be useful - there may be something in there that's "upsetting" the closing bracket or causing this issue.  &lt;/P&gt;

&lt;P&gt;Could you post the actual search please?  &lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 12:49:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375087#M110217</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2018-03-23T12:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a subsearch with multiple time ranges?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375088#M110218</link>
      <description>&lt;P&gt;[ | gentimes start=-3&lt;BR /&gt;
 | eval earliest=starttime&lt;BR /&gt;
 | eval latest=starttime+20&lt;BR /&gt;
 | eval search="*"&lt;BR /&gt;
 | fields search earliest latest&lt;BR /&gt;
 | format "index=notAnIndex earliest=-1m | append [search" "" "" "" "] | append [search" "]"&lt;BR /&gt;
 | rex field=search mode=sed "s/\"//g"]&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 12:50:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375088#M110218</guid>
      <dc:creator>aguthrie1190</dc:creator>
      <dc:date>2018-03-23T12:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a subsearch with multiple time ranges?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375089#M110219</link>
      <description>&lt;P&gt;That should get you every log for the 20 seconds between midnight and 00:00:20 for the last three days. If you want to limit that to just a specific string: &lt;/P&gt;

&lt;P&gt;[ | gentimes start=-3&lt;BR /&gt;
| eval earliest=starttime&lt;BR /&gt;
| eval latest=starttime+20&lt;BR /&gt;
| eval search="call_start"&lt;BR /&gt;
| fields search earliest latest&lt;BR /&gt;
| format "index=notAnIndex earliest=-1m | append [search" "" "" "" "] | append [search" "]"&lt;BR /&gt;
| rex field=search mode=sed "s/\"//g"]&lt;/P&gt;

&lt;P&gt;If you remove the brackets, you can see that the search is formatted properly. If you look at the job inspector it appears that the earliest/latest times are stripped from the subsearch&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 12:53:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375089#M110219</guid>
      <dc:creator>aguthrie1190</dc:creator>
      <dc:date>2018-03-23T12:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a subsearch with multiple time ranges?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375090#M110220</link>
      <description>&lt;P&gt;This seems like it is a bug. I've made a simpler search to show the behavior.&lt;/P&gt;

&lt;P&gt;This works: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[| gentimes start=-1
| eval search="* earliest=-5m"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This doesn't work: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[| gentimes start=-1
| eval search="* earliest=-5m | append [ search * earliest=-20m latest=-15m ]"]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Mar 2018 13:54:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375090#M110220</guid>
      <dc:creator>aguthrie1190</dc:creator>
      <dc:date>2018-03-23T13:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a subsearch with multiple time ranges?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375091#M110221</link>
      <description>&lt;P&gt;I’m going to be honest, i didn’t read your question throughly and I’m on mobile, but it seems like you could do this via multisearch instead of all the sub searches.&lt;/P&gt;

&lt;P&gt;| multisearch [search index=test earliest=-3d  latest=-2d] [search index=test earliest=-2d latest=-1d] | stats blah&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 00:34:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375091#M110221</guid>
      <dc:creator>dlee360</dc:creator>
      <dc:date>2018-03-27T00:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a subsearch with multiple time ranges?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375092#M110222</link>
      <description>&lt;P&gt;Unfortunately that doesn't do the trick. But I'm definitely going to start using multisearch, that seems like a lot simpler solution than append. &lt;/P&gt;

&lt;P&gt;Still, when I format that string into a subsearch, it pulls the times outside of each of the individual searches. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[| gentimes start=-3
| eval earliest=starttime
| eval latest=starttime+30
| eval search="*"
| fields search earliest latest
| format "| multisearch [search" "" "" "" "] [search" "]"
| rex field=search mode=sed "s/\"//g"
| rex field=search mode=sed "s/'/\"/g"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;leads to this error: &lt;BR /&gt;
Error in 'multisearch' command: Invalid argument: '_time&amp;gt;=1522022400.000'&lt;/P&gt;

&lt;P&gt;And this is from logs for what it's actually searching in the subsearch: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;litsearch | multisearch [search ] [search ] [search ] _time&amp;gt;=1522022400.000 _time&amp;lt;1522022430.000 
| fields keepcolorder=t "*" "_bkt" "_cd" "_si" "host" "index" "linecount" "source" "sourcetype" "splunk_server" 
| remotetl nb=300 et=1522022400.000000 lt=1522022430.000000 remove=true max_count=1000 max_prefetch=100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So that _time&amp;gt;=1522022400.000 _time&amp;lt;1522022430.000 bit is messing up the subsearch. &lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 02:53:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-create-a-subsearch-with-multiple-time-ranges/m-p/375092#M110222</guid>
      <dc:creator>aguthrie1190</dc:creator>
      <dc:date>2018-03-27T02:53:40Z</dc:date>
    </item>
  </channel>
</rss>

