<?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: Can the Returned Value From a Case Function be a Search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477097#M133914</link>
    <description>&lt;P&gt;@mayurr98 &lt;BR /&gt;
Not exactly what I am looking for.&lt;BR /&gt;
Using your example, based on &lt;STRONG&gt;field1&lt;/STRONG&gt;, &lt;STRONG&gt;dssd&lt;/STRONG&gt; needs to be a full search with &lt;EM&gt;index, source(types), hosts, booleans, rex's, evals, etc...&lt;/EM&gt;.&lt;/P&gt;

&lt;P&gt;Thanks and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
    <pubDate>Thu, 07 Nov 2019 18:09:48 GMT</pubDate>
    <dc:creator>genesiusj</dc:creator>
    <dc:date>2019-11-07T18:09:48Z</dc:date>
    <item>
      <title>Can the Returned Value From a Case Function be a Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477095#M133912</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
Can the Returned Value From a Case Function be a Search?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="pay_test"
    AND host IN ("pay20", "pay21") 
| eval priority=case("INFO1", 
    [ search index="epay_test"
        AND host IN ("pay20", "pay21")
        AND (localrefid!="" OR localrefid!="null")
        AND (token!="" OR token!="null")
        AND failCode="N"]
    ,"DEBUG1", 
    [ search index="pay_test"
        AND host IN ("pay20", "pay21")
        AND category="client.jms.DatabaseInsertMBClient"
        AND FAILCODE="N"
        AND TOTALAMOUNT!=0]) 
| table _raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is a small sample of the code. There could 10-20 or more values for the field &lt;STRONG&gt;priority&lt;/STRONG&gt;, each with their set of fields that need to examined.&lt;/P&gt;

&lt;P&gt;So is it possible to run searches dependent upon the value of a case function?&lt;/P&gt;

&lt;P&gt;BTW, the above code produced this error.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Error in 'eval' command: The expression is malformed. An unexpected character is reached at ') )'.&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Thanks and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 17:05:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477095#M133912</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2019-11-07T17:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can the Returned Value From a Case Function be a Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477096#M133913</link>
      <description>&lt;P&gt;Try this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...[search eval field2=case(field1,"dssd") | return field2]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Refer this :&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Return"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Return&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 17:29:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477096#M133913</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2019-11-07T17:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Can the Returned Value From a Case Function be a Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477097#M133914</link>
      <description>&lt;P&gt;@mayurr98 &lt;BR /&gt;
Not exactly what I am looking for.&lt;BR /&gt;
Using your example, based on &lt;STRONG&gt;field1&lt;/STRONG&gt;, &lt;STRONG&gt;dssd&lt;/STRONG&gt; needs to be a full search with &lt;EM&gt;index, source(types), hosts, booleans, rex's, evals, etc...&lt;/EM&gt;.&lt;/P&gt;

&lt;P&gt;Thanks and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 18:09:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477097#M133914</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2019-11-07T18:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can the Returned Value From a Case Function be a Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477098#M133915</link>
      <description>&lt;P&gt;Yes, using either a &lt;CODE&gt;subsearch&lt;/CODE&gt;, or &lt;CODE&gt;map&lt;/CODE&gt; but you must be very careful.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 22:33:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477098#M133915</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-11-07T22:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: Can the Returned Value From a Case Function be a Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477099#M133916</link>
      <description>&lt;P&gt;@woodcock &lt;BR /&gt;
Thanks. I updated the post above with actual code.&lt;BR /&gt;
God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2019 22:45:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477099#M133916</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2019-11-07T22:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Can the Returned Value From a Case Function be a Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477100#M133917</link>
      <description>&lt;P&gt;@woodcock&lt;BR /&gt;
From what I've seen with the &lt;STRONG&gt;map&lt;/STRONG&gt; command (which in the docs is very little; more was available in Answers) the same set of search commands is run over a number of maxsearches. This is not what I am looking for.&lt;/P&gt;

&lt;P&gt;It looks &lt;STRONG&gt;subsearch&lt;/STRONG&gt; is similar in that the same set of search commands will be run.&lt;/P&gt;

&lt;P&gt;Thanks and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 07:22:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477100#M133917</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2019-11-09T07:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Can the Returned Value From a Case Function be a Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477101#M133918</link>
      <description>&lt;P&gt;Doing more research on the &lt;STRONG&gt;case&lt;/STRONG&gt; function, I discovered it is not similar to case commands in other programming languages. It does not permit branching to another of commands. The arguments can only be field values.&lt;/P&gt;

&lt;P&gt;According to the Splunk docs, &lt;A href="https://docs.splunk.com/Documentation/Splunk/8.0.0/SearchReference/ConditionalFunctions"&gt;https://docs.splunk.com/Documentation/Splunk/8.0.0/SearchReference/ConditionalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;(Case) accepts alternating conditions and values. Returns the first value for which the condition evaluates to&lt;BR /&gt;
TRUE. a This function takes pairs of arguments X and Y. The X arguments are Boolean expressions that are evaluated&lt;BR /&gt;
from first to last. When the first X expression is encountered that evaluates to TRUE, &lt;STRONG&gt;the corresponding&lt;BR /&gt;
Y argument is returned&lt;/STRONG&gt;. The function defaults to NULL if none are true.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Y can only be an argument, and not a returned set of new search commands. &lt;/P&gt;

&lt;P&gt;Thanks and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 07:28:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477101#M133918</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2019-11-09T07:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Can the Returned Value From a Case Function be a Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477102#M133919</link>
      <description>&lt;P&gt;This helps but I am still unclear on the big picture.  What are you trying to do EXACTLY?&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 21:55:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477102#M133919</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-11-09T21:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: Can the Returned Value From a Case Function be a Search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477103#M133920</link>
      <description>&lt;P&gt;@woodcock &lt;BR /&gt;
Apologies to you and the other forum users for not responding sooner.&lt;/P&gt;

&lt;P&gt;The logs being ingested are &lt;EM&gt;sourcetype=log4j&lt;/EM&gt;, with some customization.&lt;/P&gt;

&lt;P&gt;What I need to accomplish is to have a different set of search commands run depending upon the value of the &lt;EM&gt;priority&lt;/EM&gt; field (&lt;STRONG&gt;INFO&lt;/STRONG&gt;, &lt;STRONG&gt;DEBUG&lt;/STRONG&gt;, &lt;STRONG&gt;ERROR&lt;/STRONG&gt;, etc.). I was thinking about using the &lt;EM&gt;case&lt;/EM&gt; function because I worked with case in my former programming days (Teradata SQL), and seem to remember being able to add a full set SQL (or branch to other SQL commands) based on the value of each case. However, after rereading the Splunk docs, I learned only values can be returned from a case function. Not an entire set of search commands. &lt;/P&gt;

&lt;P&gt;BTW, when I checked the &lt;STRONG&gt;map&lt;/STRONG&gt; command it appears to behave similarly to the &lt;EM&gt;for-next loop&lt;/EM&gt; structures used in other programming languages; i.e., the same set of commands would be repeated for each value of the &lt;EM&gt;priority&lt;/EM&gt; field. However, I need different SPL commands run for each different priority value. &lt;/P&gt;

&lt;P&gt;Example using 3 of the common values for the &lt;EM&gt;priority&lt;/EM&gt; field.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;INFO&lt;/STRONG&gt;: the required fields for these
events are being extracted with no
other transformations required on my end.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;ERROR&lt;/STRONG&gt;: new fields need to be extracted
requiring the &lt;EM&gt;| rex&lt;/EM&gt; command against
_raw.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;DEBUG&lt;/STRONG&gt;: requires calculations be
performed against both currently
extracted and rex'ed fields using
&lt;EM&gt;| eval&lt;/EM&gt; commands.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Therefore, I will use subsearches.&lt;/P&gt;

&lt;P&gt;How do I go about closing this post?&lt;/P&gt;

&lt;P&gt;Also, how did you format the words &lt;STRONG&gt;subsearch&lt;/STRONG&gt; and &lt;STRONG&gt;map&lt;/STRONG&gt; in your response above?&lt;/P&gt;

&lt;P&gt;Thanks and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 14:10:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-the-Returned-Value-From-a-Case-Function-be-a-Search/m-p/477103#M133920</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2019-11-12T14:10:07Z</dc:date>
    </item>
  </channel>
</rss>

