<?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 run the main search only if the subsearch returns true? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-the-main-search-only-if-the-subsearch-returns-true/m-p/211596#M61911</link>
    <description>&lt;P&gt;You can use map to simulate a conditional execution:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1
| eval lastDOM=relative_time(now(),"+1mon@mon-1d") 
| eval lastWDOM=case(strftime(lastDOM,"%a")="Sun", relative_time(lastDOM,"-2d@d"), strftime(lastDOM,"%a")="Sat", relative_time(lastDOM,"-1d@d"),1=1,lastDOM) 
| eval n_searches=if(relative_time(now(),"@d")=lastWDOM, 1, 0)
| where n_searches &amp;gt; 0
| map maxsearches=1 search="
    | search index=MyIndex queryType=\"ts\" filename=Pharmacy*.JSON 
    | table _time,accountName,filename,filesize
"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 16 Jun 2016 09:21:24 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2016-06-16T09:21:24Z</dc:date>
    <item>
      <title>How to run the main search only if the subsearch returns true?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-the-main-search-only-if-the-subsearch-returns-true/m-p/211594#M61909</link>
      <description>&lt;P&gt;I have to run the Main search only on the last working day of the month, and I got to a search that should work, but the main search is not taking the boolean response of subsearch as a condition to process the rest of the search.&lt;/P&gt;

&lt;P&gt;Here is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=MyIndex queryType="ts" filename=Pharmacy*.JSON [| gentimes start=-1 | eval lastDOM=relative_time(now(),"+1mon@mon-1d") | eval lastWDOM=case(strftime(lastDOM,"%a")="Sun", relative_time(lastDOM,"-2d@d"),strftime(lastDOM,"%a")="Sat", relative_time(lastDOM,"-1d@d"),1=1,lastDOM) | eval query=if(relative_time(now(),"@d")=lastWDOM,1=1,1=2) | table query] | table _time,accountName,filename,filesize 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:28:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-the-main-search-only-if-the-subsearch-returns-true/m-p/211594#M61909</guid>
      <dc:creator>prakashbhanu407</dc:creator>
      <dc:date>2016-06-15T22:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to run the main search only if the subsearch returns true?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-the-main-search-only-if-the-subsearch-returns-true/m-p/211595#M61910</link>
      <description>&lt;P&gt;You cannot assign boolean values to a field.  Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=MyIndex queryType="ts" filename=Pharmacy*.JSON earliest=[| gentimes start=-1 | addinfo | eval lastDOM=relative_time(now(),"+1mon@mon-1d") | eval lastWDOM=case(strftime(lastDOM,"%a")="Sun", relative_time(lastDOM,"-2d@d"),strftime(lastDOM,"%a")="Sat", relative_time(lastDOM,"-1d@d"),true(),lastDOM) | eval earliest=if(relative_time(now(),"@d")=lastWDOM,"Do Not Run",info_min_time) | return $earliest] | table _time accountName filename filesize
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will cause the search to crash if it does not meet your criteria.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:59:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-the-main-search-only-if-the-subsearch-returns-true/m-p/211595#M61910</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-06-15T22:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to run the main search only if the subsearch returns true?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-the-main-search-only-if-the-subsearch-returns-true/m-p/211596#M61911</link>
      <description>&lt;P&gt;You can use map to simulate a conditional execution:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1
| eval lastDOM=relative_time(now(),"+1mon@mon-1d") 
| eval lastWDOM=case(strftime(lastDOM,"%a")="Sun", relative_time(lastDOM,"-2d@d"), strftime(lastDOM,"%a")="Sat", relative_time(lastDOM,"-1d@d"),1=1,lastDOM) 
| eval n_searches=if(relative_time(now(),"@d")=lastWDOM, 1, 0)
| where n_searches &amp;gt; 0
| map maxsearches=1 search="
    | search index=MyIndex queryType=\"ts\" filename=Pharmacy*.JSON 
    | table _time,accountName,filename,filesize
"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Jun 2016 09:21:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-the-main-search-only-if-the-subsearch-returns-true/m-p/211596#M61911</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-06-16T09:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to run the main search only if the subsearch returns true?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-the-main-search-only-if-the-subsearch-returns-true/m-p/211597#M61912</link>
      <description>&lt;P&gt;Try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=MyIndex queryType="ts" filename=Pharmacy*.JSON [| gentimes start=-1 | eval lastDOM=relative_time(now(),"+1mon@mon-1d") | eval lastWDOM=case(strftime(lastDOM,"%a")="Sun", relative_time(lastDOM,"-2d@d"),strftime(lastDOM,"%a")="Sat", relative_time(lastDOM,"-1d@d"),1=1,lastDOM) | eval index=if(relative_time(now(),"@d")=lastWDOM,"MyIndex","YouWillNotFindThisIndex") | table index] | table _time,accountName,filename,filesize
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically, if the subsearch condition is false, it'll return a value for field (metadata field used for better performance) index which may never exist so main search will not run. It returns the same index name as main search in case the condition is true.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2016 16:35:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-the-main-search-only-if-the-subsearch-returns-true/m-p/211597#M61912</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-06-16T16:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to run the main search only if the subsearch returns true?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-run-the-main-search-only-if-the-subsearch-returns-true/m-p/211598#M61913</link>
      <description>&lt;P&gt;I couldn't thank much on using map, it solved my long standing issue.. thanks alot..&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2017 02:34:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-run-the-main-search-only-if-the-subsearch-returns-true/m-p/211598#M61913</guid>
      <dc:creator>ibob0304</dc:creator>
      <dc:date>2017-05-04T02:34:14Z</dc:date>
    </item>
  </channel>
</rss>

