<?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: Best practices when using subsearch (eval, etc) in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Best-practices-when-using-subsearch-eval-etc/m-p/139997#M38575</link>
    <description>&lt;P&gt;I think the general answer to your question is that you should try to avoid using a &lt;CODE&gt;subsearch&lt;/CODE&gt; whenever possible.  The minor reason is performance but the major reason is that it has some hard limits that cannot be overcome.  In the case of a &lt;CODE&gt;join&lt;/CODE&gt;-type problem, you should bend over backwards to use &lt;CODE&gt;stats&lt;/CODE&gt; instead and this is usually possible.  In the case of the example you gave, if the subsearch spans a large set of events (a long period of time) and/or you are going to run the same search frequently, it would probably be best to schedule a separate saved-search and write the results of the animal count to a lookup file using the &lt;CODE&gt;outputlookup&lt;/CODE&gt; command and then your search would look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval cowStatus=if([|inputlookup animal_counts.csv | where animal="cow" | return $count] &amp;gt; 50, "Cow overload!", "All cool")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 03 Aug 2015 12:53:18 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2015-08-03T12:53:18Z</dc:date>
    <item>
      <title>Best practices when using subsearch (eval, etc)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Best-practices-when-using-subsearch-eval-etc/m-p/139994#M38572</link>
      <description>&lt;P&gt;I am relatively new to Splunk and would like to get a better sense of using subsearch as I can see how valuable it must be if you could fully utilize it. I would like to know some of the best practices when using subsearch in general but more specifically within eval-statements, how to think in order to get the right data out of the subsearch.&lt;/P&gt;

&lt;P&gt;What does a subsearch actually return? It of course depends on what you put in the search query but how does an eval-statement interpret the result? Depending on if the subsearch ends with return, table someValue, head 1 or just a bunch of event or statistic-lines, how it is interpreted? How does a subsearch result containing multiple fields differ from a subsearch that only returns one field?&lt;/P&gt;

&lt;P&gt;What are the best practices for returning a specific value of a field to use within an if statement? Something like this: &lt;CODE&gt;eval cowStatus=if([subsearch returning current number of cows] &amp;amp;gt; 50, "Cow overload!", "All cool")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I hope my questions are not to broad.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 12:31:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Best-practices-when-using-subsearch-eval-etc/m-p/139994#M38572</guid>
      <dc:creator>ohlafl</dc:creator>
      <dc:date>2015-07-28T12:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Best practices when using subsearch (eval, etc)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Best-practices-when-using-subsearch-eval-etc/m-p/139995#M38573</link>
      <description>&lt;P&gt;It seems to be a pretty broad question... it sounds like you could be looking for the documentation on the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.4/SearchReference/return"&gt;return&lt;/A&gt; command or for the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.4/SearchReference/format"&gt;format&lt;/A&gt; command docs, which is used implicitly at the end of a subsearch? Or for the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.4/Search/Changetheformatofsubsearchresults"&gt;docs on how to change subsearch results&lt;/A&gt;?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2015 12:59:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Best-practices-when-using-subsearch-eval-etc/m-p/139995#M38573</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-07-28T12:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Best practices when using subsearch (eval, etc)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Best-practices-when-using-subsearch-eval-etc/m-p/139996#M38574</link>
      <description>&lt;P&gt;In general, the subsearch would return the results of a search, and the format is also decided by the code/subsearch query (you code that based on your requirement of subsearch usage)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;e.g. index=_internal [search index=_internal | top 2 sourcetypes | table sourcetype]  
 **This will return results with a field name 'sourcetype' and add as filter condition. so the resulting search would become (sample)
index=_internal (sourcetype=splunkd OR sourcetype=splunkd_access)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Same this if you reduce the result count of subsearch to 1 and use return,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal [search index=_internal | top 1 sourcetypes | return $sourcetype ] 
**This would return a string with value of sourcetype into the place its used. SO the resulting search would become (sample) [THis is what we used when using subsearch with eval]
index=_internal "splunkd" 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jul 2015 14:48:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Best-practices-when-using-subsearch-eval-etc/m-p/139996#M38574</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-07-28T14:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Best practices when using subsearch (eval, etc)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Best-practices-when-using-subsearch-eval-etc/m-p/139997#M38575</link>
      <description>&lt;P&gt;I think the general answer to your question is that you should try to avoid using a &lt;CODE&gt;subsearch&lt;/CODE&gt; whenever possible.  The minor reason is performance but the major reason is that it has some hard limits that cannot be overcome.  In the case of a &lt;CODE&gt;join&lt;/CODE&gt;-type problem, you should bend over backwards to use &lt;CODE&gt;stats&lt;/CODE&gt; instead and this is usually possible.  In the case of the example you gave, if the subsearch spans a large set of events (a long period of time) and/or you are going to run the same search frequently, it would probably be best to schedule a separate saved-search and write the results of the animal count to a lookup file using the &lt;CODE&gt;outputlookup&lt;/CODE&gt; command and then your search would look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval cowStatus=if([|inputlookup animal_counts.csv | where animal="cow" | return $count] &amp;gt; 50, "Cow overload!", "All cool")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Aug 2015 12:53:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Best-practices-when-using-subsearch-eval-etc/m-p/139997#M38575</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-03T12:53:18Z</dc:date>
    </item>
  </channel>
</rss>

