<?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 write a search where if a specific value for FIELD1 is present in subsearch results, run Search1, but if not, run Search2? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146639#M40954</link>
    <description>&lt;P&gt;I know this question is old, but you could do it using the command map (no, it doesn't have to do with geografic maps).. &lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/SplunkCloud/6.6.1/SearchReference/Map"&gt;https://docs.splunk.com/Documentation/SplunkCloud/6.6.1/SearchReference/Map&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2017 13:10:29 GMT</pubDate>
    <dc:creator>pamcarvalho</dc:creator>
    <dc:date>2017-09-28T13:10:29Z</dc:date>
    <item>
      <title>How to write a search where if a specific value for FIELD1 is present in subsearch results, run Search1, but if not, run Search2?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146634#M40949</link>
      <description>&lt;P&gt;I have a search which has a field (say FIELD1). I would like to search the presence of a FIELD1 value in subsearch. If that FIELD1 value is present in subsearch results, then do work-1 (remaining search will change in direction-1), otherwise do work-2 (remaining search will change in direction-2).&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;pseudo search query:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="sample_index" sourcetype="sample_sourcetype"| fields FIELD1 | search FIELD1 in [my sub search here| fields FIELD1] | if FIELD1 is present in subsearch, then do work-1, If not do work-2.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I looked at &lt;A href="https://answers.splunk.com/answers/31842/why-cant-i-use-subsearch-in-the-case-function-in-the-eval-command.html"&gt;https://answers.splunk.com/answers/31842/why-cant-i-use-subsearch-in-the-case-function-in-the-eval-command.html&lt;/A&gt;&lt;BR /&gt;
But, this is talking about comparing single value with single value from subsearch. What I am looking is finding FIELD1 value in multiple results of subsearch.&lt;/P&gt;

&lt;P&gt;Any suggestions to proceed further?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2015 12:29:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146634#M40949</guid>
      <dc:creator>kasu_praveen</dc:creator>
      <dc:date>2015-04-17T12:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search where if a specific value for FIELD1 is present in subsearch results, run Search1, but if not, run Search2?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146635#M40950</link>
      <description>&lt;P&gt;Hi, I think you can do it like this:&lt;BR /&gt;
1- you write a search1 that track FIELD1 (you can use a regex for that ) and put the result in a variable let's say VAR&lt;/P&gt;

&lt;P&gt;2- you pipe search1 and use eval command with if()  .&lt;/P&gt;

&lt;P&gt;3- in the funtion if( ) , at the place of conditionals results you put subsearches.&lt;/P&gt;

&lt;P&gt;4- all the previous steps will look like this:&lt;/P&gt;

&lt;P&gt;index=....  sourcetype=...  search1 |eval result=if( VAR="FIELD1" ,[subsearch1|return $result1 ] , [subsearch2l return $result2] ) | table result&lt;/P&gt;

&lt;P&gt;5-note that if you have many conditions you can imbricate if() like this:  &lt;/P&gt;

&lt;P&gt;if( condition, if(....), [ ] )&lt;/P&gt;

&lt;P&gt;6-  this is a small example using splunk internal event:&lt;/P&gt;

&lt;P&gt;index=&lt;EM&gt;*  | eval result=if( host != "myPc" , [search index=&lt;/EM&gt;* |stats dc(host) as cc|return $cc] , [ search index=_* |stats c(source) as cs |return $cs] ) | table result&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2015 03:38:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146635#M40950</guid>
      <dc:creator>stephane_cyrill</dc:creator>
      <dc:date>2015-04-18T03:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search where if a specific value for FIELD1 is present in subsearch results, run Search1, but if not, run Search2?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146636#M40951</link>
      <description>&lt;P&gt;Thanks for your response @stephane_cyrille, What I was looking is slightly different.&lt;/P&gt;

&lt;P&gt;Once I got FIELD1 from search1, I need to search for that value in a subsearch. &lt;BR /&gt;
If FIELD1 is found in subsearch then proceed with SUBSEARCH1, if not SUBSEARCH2.&lt;/P&gt;

&lt;P&gt;So, instead of simply comparing apple to apple (host!="mypc"), Is there a way I can search for FIELD1 value in subsearch?&lt;/P&gt;

&lt;P&gt;Explaining In another detailed way, I have 4 searches (SEARCH1 ,SEARCH2 ,SEARCH3 ,SEARCH4). &lt;BR /&gt;
 1. I will get FIELD1 from SEARCH1.&lt;BR /&gt;
 2. Search FIELD1 values in SEARCH2, If found do SEARCH3, If not SEARCH4&lt;/P&gt;

&lt;P&gt;Thanks for your time and interest on this. Truly appreciated. &lt;BR /&gt;
Early response will be much more helpful for me.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2015 07:20:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146636#M40951</guid>
      <dc:creator>kasu_praveen</dc:creator>
      <dc:date>2015-04-23T07:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search where if a specific value for FIELD1 is present in subsearch results, run Search1, but if not, run Search2?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146637#M40952</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;|multisearch 
 [search &amp;lt;your base search1&amp;gt; here you track FIELD1 and put the result in VAR1] 
 [search &amp;lt;your base search&amp;gt; here you track FIELD1 and put the result in VAR2 ] 
 | eval result=if(VAR1==VAR2, [SEARCH3|return $result1]  ,[SEARCH3|return $result2])
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;take a look on return command in Search Reference manual.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2015 08:45:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146637#M40952</guid>
      <dc:creator>stephane_cyrill</dc:creator>
      <dc:date>2015-04-23T08:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search where if a specific value for FIELD1 is present in subsearch results, run Search1, but if not, run Search2?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146638#M40953</link>
      <description>&lt;P&gt;This seems to be the approach. &lt;BR /&gt;
My Query had issues, because of other searches (SEARCH3 and SEARCH4). &lt;/P&gt;

&lt;P&gt;Thanks for your time Stephane_cyrille&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2015 06:01:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146638#M40953</guid>
      <dc:creator>kasu_praveen</dc:creator>
      <dc:date>2015-04-28T06:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search where if a specific value for FIELD1 is present in subsearch results, run Search1, but if not, run Search2?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146639#M40954</link>
      <description>&lt;P&gt;I know this question is old, but you could do it using the command map (no, it doesn't have to do with geografic maps).. &lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/SplunkCloud/6.6.1/SearchReference/Map"&gt;https://docs.splunk.com/Documentation/SplunkCloud/6.6.1/SearchReference/Map&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 13:10:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/146639#M40954</guid>
      <dc:creator>pamcarvalho</dc:creator>
      <dc:date>2017-09-28T13:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search where if a specific value for FIELD1 is present in subsearch results, run Search1, but if not,</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/521689#M147013</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/32501"&gt;@stephane_cyrill&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have run a quick try as your approach but it got only one field return and I need to remove all non streaming command. Do you have another approach to advice?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 06:08:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/521689#M147013</guid>
      <dc:creator>thuhuongle</dc:creator>
      <dc:date>2020-09-28T06:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search where if a specific value for FIELD1 is present in subsearch results, run Search1, but if not,</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/582670#M202933</link>
      <description>&lt;P&gt;Hi, can someone please provide a query for this? I am also looking for something similar. I want a search to retrieve value(VAR1) of FEILD1 and then write search2 with that value(VAR1).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 06:17:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-where-if-a-specific-value-for-FIELD1-is/m-p/582670#M202933</guid>
      <dc:creator>sayleekamthe</dc:creator>
      <dc:date>2022-01-27T06:17:44Z</dc:date>
    </item>
  </channel>
</rss>

