<?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 edit my search so if my subsearch returns no results, my main search returns all events from index=&amp;quot;test&amp;quot;? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-edit-my-search-so-if-my-subsearch-returns-no-results/m-p/201008#M58270</link>
    <description>&lt;P&gt;Hi rmuraly,&lt;/P&gt;

&lt;P&gt;You should avoid sub searches, because they are slow and will hit limits as soon as you put real data volumes through them. Try a simple conditional eval on this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="test" OR index="test_summary"
| eval y_time=if(index="test_summary" AND key_field="y", _time, 0)
| stats max(y_time) AS y_time max(_time) as _time by _time (add any other fields needed further down the pipe ...)
| where _time &amp;gt; y_time
| do more splunk-fu here ....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This may or may not provide a solution to you, but it for sure shows a way to go. You can read more on this topic in this answer &lt;A href="https://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html"&gt;https://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html&lt;/A&gt; or in the March session of the Virtual .conf here &lt;A href="http://wiki.splunk.com/Virtual_.conf"&gt;http://wiki.splunk.com/Virtual_.conf&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
    <pubDate>Mon, 19 Sep 2016 23:53:28 GMT</pubDate>
    <dc:creator>MuS</dc:creator>
    <dc:date>2016-09-19T23:53:28Z</dc:date>
    <item>
      <title>How can I edit my search so if my subsearch returns no results, my main search returns all events from index="test"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-edit-my-search-so-if-my-subsearch-returns-no-results/m-p/201006#M58268</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index="test"  [search index="test_summary" key_field="y" | head 1 | eval search = "_time&amp;gt;" . _time | fields search]
| table a,b,c
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have to return everything under "test" where _time&amp;gt;_time of y_summary. This search works fine as long as there is something under test_summary with &lt;STRONG&gt;key_field="y"&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;But, if there are no events returned by the sub search, my main search should return all the items in the index="test"&lt;/P&gt;

&lt;P&gt;How do I get it working.. I have been on this for a day now.. with very little progress to show..&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:02:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-edit-my-search-so-if-my-subsearch-returns-no-results/m-p/201006#M58268</guid>
      <dc:creator>rmuraly</dc:creator>
      <dc:date>2020-09-29T11:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: How can I edit my search so if my subsearch returns no results, my main search returns all events from index="test"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-edit-my-search-so-if-my-subsearch-returns-no-results/m-p/201007#M58269</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="test" [search index="test_summary" key_field="y" | head 1 | eval earliest=_time | append [ | makeresults | eval earliest=0] | head 1 | return earliest ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Sep 2016 23:47:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-edit-my-search-so-if-my-subsearch-returns-no-results/m-p/201007#M58269</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-09-19T23:47:02Z</dc:date>
    </item>
    <item>
      <title>Re: How can I edit my search so if my subsearch returns no results, my main search returns all events from index="test"?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-edit-my-search-so-if-my-subsearch-returns-no-results/m-p/201008#M58270</link>
      <description>&lt;P&gt;Hi rmuraly,&lt;/P&gt;

&lt;P&gt;You should avoid sub searches, because they are slow and will hit limits as soon as you put real data volumes through them. Try a simple conditional eval on this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="test" OR index="test_summary"
| eval y_time=if(index="test_summary" AND key_field="y", _time, 0)
| stats max(y_time) AS y_time max(_time) as _time by _time (add any other fields needed further down the pipe ...)
| where _time &amp;gt; y_time
| do more splunk-fu here ....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This may or may not provide a solution to you, but it for sure shows a way to go. You can read more on this topic in this answer &lt;A href="https://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html"&gt;https://answers.splunk.com/answers/129424/how-to-compare-fields-over-multiple-sourcetypes-without-join-append-or-use-of-subsearches.html&lt;/A&gt; or in the March session of the Virtual .conf here &lt;A href="http://wiki.splunk.com/Virtual_.conf"&gt;http://wiki.splunk.com/Virtual_.conf&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 23:53:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-edit-my-search-so-if-my-subsearch-returns-no-results/m-p/201008#M58270</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2016-09-19T23:53:28Z</dc:date>
    </item>
  </channel>
</rss>

