<?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 do I dynamically set earliest from subsearch? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334322#M99356</link>
    <description>&lt;P&gt;This worked. It looks like it does the same thing as my first subsearch attempt, how do these differ?&lt;/P&gt;</description>
    <pubDate>Wed, 13 Sep 2017 18:22:35 GMT</pubDate>
    <dc:creator>richarddicaire</dc:creator>
    <dc:date>2017-09-13T18:22:35Z</dc:date>
    <item>
      <title>How do I dynamically set earliest from subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334320#M99354</link>
      <description>&lt;P&gt;Hi folks, been all over this site and google, not finding a working solution.&lt;/P&gt;

&lt;P&gt;I'm trying to perform a search using a subsearch to populate earliest=&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats min(_indextime) as firstTime, max(_indextime) as lastTime where earliest=[ | rest /services/admin/indexes splunk_server=localhost
| search title=syslog | eval dy = (frozenTimePeriodInSecs/86400) | eval earli="-" . dy . "d@d" |fields earli ] index=syslog by index
| eval delta = (lastTime - firstTime) | eval yr = floor(delta/86400/365)| eval dy = (delta/86400) % 365 | eval actual_ret = yr . " years, " . dy . " days"
| eval lastTime=strftime(lastTime,"%Y-%m-%d %H:%M:%S"), firstTime=strftime(firstTime,"%Y-%m-%d %H:%M:%S") | fields index, firstTime, lastTime, delta, actual_ret
| join index [| rest /services/admin/indexes splunk_server=localhost | eval yr = floor(frozenTimePeriodInSecs/86400/365)
| eval dy = (frozenTimePeriodInSecs/86400) % 365 | eval ret = yr . " years, " . dy . " days" | eval index=title
| stats avg(currentDBSizeMB) as currentDBSizeMB, avg(maxTotalDataSizeMB) as maxTotalDataSizeMB, max(frozenTimePeriodInSecs) as frozenTimePeriodInSecs, max(ret) by index
| eval pct_data=(currentDBSizeMB/maxTotalDataSizeMB) * 100] | eval pct_ret = (delta/frozenTimePeriodInSecs)*100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and get error &lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Invalid value "(" for time term 'earliest'&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Also tried subsearch&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=[ | rest /services/admin/indexes splunk_server=localhost
| search title=syslog | eval dy = (frozenTimePeriodInSecs/86400) | fields dy ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with same result. Both subsearches by themselves return correct results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rest /services/admin/indexes splunk_server=localhost
| search title=syslog | eval dy = (frozenTimePeriodInSecs/86400) | eval earli="-" . dy . "d@d" |fields earli

returns

-365d@d

and

| rest /services/admin/indexes splunk_server=localhost
| search title=syslog | eval dy = (frozenTimePeriodInSecs/86400) | fields dy

returns

365
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I get the subsearch value to be used by "earliest="?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 17:37:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334320#M99354</guid>
      <dc:creator>richarddicaire</dc:creator>
      <dc:date>2017-09-13T17:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I dynamically set earliest from subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334321#M99355</link>
      <description>&lt;P&gt;&lt;CODE&gt;earliest&lt;/CODE&gt; has to be in either relative form, or in epoch form.  Try this.,,,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; earliest=[ | rest /services/admin/indexes splunk_server=localhost
| search title=syslog 
| eval search = "-".tostring(floor(frozenTimePeriodInSecs/86400))."d@d" | table search]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;NOTE - When you get to the end of a subsearch, the subsearch will return either whatever is in the field &lt;CODE&gt;search&lt;/CODE&gt;.  If there is no such field, the subsearch will implicitly invoke the &lt;CODE&gt;format&lt;/CODE&gt; command and return whatever fields (field1, field2...) and values are in each record in the format... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;( ( field1="value1fromrecord1" AND field2="value2fromrecord1"... ) OR  ( field1="value1fromrecord2" AND field2="value2fromrecord2"... )  OR ...) )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... which in your case, with one field named dy and a value we'll call 1234, meant it returned...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;( ( dy="1234" ) ) 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2017 17:58:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334321#M99355</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-09-13T17:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I dynamically set earliest from subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334322#M99356</link>
      <description>&lt;P&gt;This worked. It looks like it does the same thing as my first subsearch attempt, how do these differ?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 18:22:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334322#M99356</guid>
      <dc:creator>richarddicaire</dc:creator>
      <dc:date>2017-09-13T18:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I dynamically set earliest from subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334323#M99357</link>
      <description>&lt;P&gt;@richarddicaire - I already explained that after the horizontal bar.  You can play with the &lt;CODE&gt;format&lt;/CODE&gt; command at the end of any search to see what exactly will be returned.  In this specific case, your original code returned something that looked like &lt;CODE&gt;( ( dy="1234" ) )&lt;/CODE&gt;  hence, the message that &lt;CODE&gt;"("&lt;/CODE&gt; was an invalid value.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 18:35:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334323#M99357</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-09-13T18:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I dynamically set earliest from subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334324#M99358</link>
      <description>&lt;P&gt;I understood that, thats the result returned from my second subsearch attempt, I was asking about the difference between between your working result, and my first subsearch attempt.&lt;/P&gt;

&lt;P&gt;After checking with &lt;CODE&gt;format&lt;/CODE&gt;, I'm seeing my first subsearch returned &lt;CODE&gt;( ( earli="-365d@d" ) )&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;Thanks for the explanation, and using format as well.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 18:48:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334324#M99358</guid>
      <dc:creator>richarddicaire</dc:creator>
      <dc:date>2017-09-13T18:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I dynamically set earliest from subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334325#M99359</link>
      <description>&lt;P&gt;@richarddicaire - ah, I misunderstood.  Yes, &lt;CODE&gt;format&lt;/CODE&gt; is great to play with.  I very often end up using &lt;CODE&gt;format&lt;/CODE&gt; with unique arguments, then using &lt;CODE&gt;| rex field=search mode=sed "some rex"&lt;/CODE&gt; to change the results in field &lt;CODE&gt;search&lt;/CODE&gt; to exactly what I need to return. &lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 22:10:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-dynamically-set-earliest-from-subsearch/m-p/334325#M99359</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-09-13T22:10:52Z</dc:date>
    </item>
  </channel>
</rss>

