<?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: return command - exit (or return known value) if no results found in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51874#M12589</link>
    <description>&lt;P&gt;Not sure if that syntax is quite correct, but the idea works and I cant find anything better - thanks cramasta!&lt;/P&gt;</description>
    <pubDate>Tue, 04 Jun 2013 06:53:51 GMT</pubDate>
    <dc:creator>thewer</dc:creator>
    <dc:date>2013-06-04T06:53:51Z</dc:date>
    <item>
      <title>return command - exit (or return known value) if no results found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51872#M12587</link>
      <description>&lt;P&gt;I have a search that is basically (there are actually 2 sub searches, but this makes it easier to understand):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="weblogs" [ SEARCH index="custcomplaintlogs" earliest=-1d | return 50 $custsession ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This normally returns the weblogs that contain any of the customer sessions where the customers complained (ie: find what the complaining customer actually did on the site). However when there are no results in "custcomplaintlogs" over the last day it returns EVERYTHING from "weblogs". If there is something in "custcomplaintlogs" it will give the weblogs for the customers session only.&lt;/P&gt;

&lt;P&gt;How can I stop it returning everything if the subsearch has no results. I want to either exit, or return something that will match nothing in the weblogs.&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2013 08:08:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51872#M12587</guid>
      <dc:creator>thewer</dc:creator>
      <dc:date>2013-05-31T08:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: return command - exit (or return known value) if no results found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51873#M12588</link>
      <description>&lt;P&gt;Not sure if there is a better way, but what if you did something like this&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index="weblogs" [ SEARCH index="custcomplaintlogs" earliest=-1d | append [earliest=-1s |stats count | eval custsession="NeverEverGonnaFindMeInSplunk" | fields custsession]| return 50 $custsession ]&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;This will basically just add another value to custsession which will never be found in splunk. If your subsearch doesn't return any values with the return command it will at least always return NeverEverGonnaFindMeInSplunk which will stop the main search from searching for everything&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2013 20:06:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51873#M12588</guid>
      <dc:creator>cramasta</dc:creator>
      <dc:date>2013-05-31T20:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: return command - exit (or return known value) if no results found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51874#M12589</link>
      <description>&lt;P&gt;Not sure if that syntax is quite correct, but the idea works and I cant find anything better - thanks cramasta!&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2013 06:53:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51874#M12589</guid>
      <dc:creator>thewer</dc:creator>
      <dc:date>2013-06-04T06:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: return command - exit (or return known value) if no results found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51875#M12590</link>
      <description>&lt;P&gt;Yeah forgot an additional end bracket at the end of the fields command. I updated the post.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2013 13:51:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51875#M12590</guid>
      <dc:creator>cramasta</dc:creator>
      <dc:date>2013-06-04T13:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: return command - exit (or return known value) if no results found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51876#M12591</link>
      <description>&lt;P&gt;thanks! it worked by eval new row with 0 value and put it at the and of the resulting table, requesting "head 1". Then if the search is empty then only that last 0 come that I can take within the rest of the code.&lt;/P&gt;

&lt;P&gt;i.e &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myIndex" | where pString = "xyz" | append [ | stats count | fields - count | eval pString = 0  ] | eval recs=if(pString=0,0,1) | sort recs DESC | head 1 | table pString
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Dec 2016 19:57:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51876#M12591</guid>
      <dc:creator>unchura</dc:creator>
      <dc:date>2016-12-14T19:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: return command - exit (or return known value) if no results found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51877#M12592</link>
      <description>&lt;P&gt;Would probably be better if you did this instead:&lt;/P&gt;

&lt;P&gt;index="weblogs" [ SEARCH index="custcomplaintlogs" earliest=-1d | append [earliest=-1s |stats count | eval custsession=if(isnull(custsession,"null",custsession) | fields custsession]| return 50 $custsession ]&lt;/P&gt;

&lt;P&gt;or&lt;/P&gt;

&lt;P&gt;index="weblogs" [ SEARCH index="custcomplaintlogs" earliest=-1d | append [earliest=-1s |stats count | fillnull custsession | fields custsession]| return 50 $custsession ]&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2017 14:29:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/return-command-exit-or-return-known-value-if-no-results-found/m-p/51877#M12592</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2017-04-14T14:29:53Z</dc:date>
    </item>
  </channel>
</rss>

