<?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 Conditional search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Conditional-search/m-p/62985#M15548</link>
    <description>&lt;P&gt;I have 2 fields that I need to search on - Field1 and Field2. Most of the time I only want to search on Field1 but occasionally it contains a value which means I need to also search for Field2. I have a rex statement which populates a variable when Field1 contains the keyword so I need my search to look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex KeywordFound=(find the key word) |
if KeywordFound is null search for Field1
else search for Field1 and Field2 |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can this kind of conditional search be done with Splunk?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 02 Feb 2012 12:39:03 GMT</pubDate>
    <dc:creator>Bulluk</dc:creator>
    <dc:date>2012-02-02T12:39:03Z</dc:date>
    <item>
      <title>Conditional search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-search/m-p/62985#M15548</link>
      <description>&lt;P&gt;I have 2 fields that I need to search on - Field1 and Field2. Most of the time I only want to search on Field1 but occasionally it contains a value which means I need to also search for Field2. I have a rex statement which populates a variable when Field1 contains the keyword so I need my search to look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex KeywordFound=(find the key word) |
if KeywordFound is null search for Field1
else search for Field1 and Field2 |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can this kind of conditional search be done with Splunk?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2012 12:39:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-search/m-p/62985#M15548</guid>
      <dc:creator>Bulluk</dc:creator>
      <dc:date>2012-02-02T12:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-search/m-p/62986#M15549</link>
      <description>&lt;P&gt;Do you need just to search for the general existence of Field1 and Field2?&lt;/P&gt;

&lt;P&gt;I imagine you could use a subsearch to accomplish this. You start off the outer search with searching for Field1 and then use the subsearch for adding a search for Field2 if the subsearch finds the keyword. Something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Field1=* [search * | rex (?&amp;lt;KeywordFound&amp;gt;blahblah) | search KeywordFound=* | head 1 | eval query="Field2=*" | fields query]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Feb 2012 13:04:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-search/m-p/62986#M15549</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-02-02T13:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-search/m-p/62987#M15550</link>
      <description>&lt;P&gt;I'm not completely following your logic but you post has given me an idea that should work. When KeywordFound is null I'll evaluate Field2 to a wildcard so that all events match, meaning the only field actually being used in the search is Field1.&lt;/P&gt;

&lt;P&gt;I'm off to try out the theory. If it works I shall award the points &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2012 13:40:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-search/m-p/62987#M15550</guid>
      <dc:creator>Bulluk</dc:creator>
      <dc:date>2012-02-02T13:40:47Z</dc:date>
    </item>
  </channel>
</rss>

