<?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 does OR work with strings? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-does-OR-work-with-strings/m-p/564207#M196528</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/171870"&gt;@pm771&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;the two condition you shared are different because:&lt;/P&gt;&lt;P&gt;the first is:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| WHERE (somefield = string1) OR (string2)&lt;/LI-CODE&gt;&lt;P&gt;in other words, you have an OR condition between the condition "somefield=string1" and the search string "string2";&lt;/P&gt;&lt;P&gt;The second one is instead:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| WHERE (somefield = string1) OR (somefield=string2)&lt;/LI-CODE&gt;&lt;P&gt;so you have an OR condition between "somefield=string1" and "somefield=string2".&lt;/P&gt;&lt;P&gt;In other words the second condition is similar but more strong than the first.&lt;/P&gt;&lt;P&gt;The OR condition can work using strings and pairs field=value as you need.&lt;/P&gt;&lt;P&gt;For more infos see at&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/SCS/current/Search/Predicates#Logical_operators" target="_blank"&gt;https://docs.splunk.com/Documentation/SCS/current/Search/Predicates#Logical_operators&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
    <pubDate>Sun, 22 Aug 2021 08:09:47 GMT</pubDate>
    <dc:creator>gcusello</dc:creator>
    <dc:date>2021-08-22T08:09:47Z</dc:date>
    <item>
      <title>How does OR work with strings?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-OR-work-with-strings/m-p/564197#M196524</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I noticed that&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;... WHERE somefield = string1 OR string2&lt;/LI-CODE&gt;&lt;P&gt;works the same way as&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;... WHERE somefield = string1 OR somefield=string2&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Why is it so? How &lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;OR&lt;/STRONG&gt;&lt;/FONT&gt; works with strings?&lt;/P&gt;</description>
      <pubDate>Sat, 21 Aug 2021 16:36:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-OR-work-with-strings/m-p/564197#M196524</guid>
      <dc:creator>pm771</dc:creator>
      <dc:date>2021-08-21T16:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: How does OR work with strings?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-OR-work-with-strings/m-p/564200#M196525</link>
      <description>&lt;P&gt;Are you sure they're the same?&amp;nbsp; Create an event with &lt;FONT face="courier new,courier"&gt;otherfield=string2&lt;/FONT&gt; and then try those two queries again.&amp;nbsp; I think you'll find they're different.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Aug 2021 19:42:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-OR-work-with-strings/m-p/564200#M196525</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-08-21T19:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: How does OR work with strings?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-OR-work-with-strings/m-p/564204#M196527</link>
      <description>&lt;P&gt;Unfortunately it is not clear which SPL command you are using here (or if you're talking about before the first pipe and therefore the &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/search" target="_blank" rel="noopener"&gt;search command&lt;/A&gt;&amp;nbsp;itself), and that is important because semantics can be different for each.&lt;BR /&gt;&lt;BR /&gt;To let folks follow along, I'm going to make some sample data like so, and call this my &amp;lt;base&amp;gt; query:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval somefield=split("one;two;three;four",";"), lol="where", otherfield="three", thirdfield="five"
| mvexpand somefield 
| collect testmode=true 
| fields - lol&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using this you'll see we have 4 results, with three extracted fields, and a raw body of some sample data. We can then follow this with other commands and talk about what they do / how they work.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So let's talk about the search command:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base&amp;gt;
| search WHERE somefield = one OR two&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;If you execute this, you'll get back two results. But what's actually going on here, is we're looking for events whose _raw field contains the word "where"&amp;nbsp; AND ( either has a called somefield set to the value "one" OR whose _raw field contains the value "two" ) . WHERE is not a keyword for the search command, and so is being treated as like just another word.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;You'll see that we can get rid of the "WHERE" in this command, and it works just the same. (Again, other SPL commands may have other semantics)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base&amp;gt;
| search somefield = one OR two&lt;/LI-CODE&gt;&lt;P&gt;Same two results come back&lt;BR /&gt;&lt;BR /&gt;Now realizing that the raw string is being looked for as a term in _raw may become more apparent if we&amp;nbsp;change "two" to "five", i.e.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base&amp;gt;
| search somefield = one OR five&lt;/LI-CODE&gt;&lt;P&gt;And now we get all rows back because while somefield didn't contain "five" the text of the raw event does (namely as part of thirdfield)&lt;BR /&gt;&lt;BR /&gt;And the importance of keywords with search may also become apparent when we change the OR to lowercase:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base&amp;gt;
| search somefield = one or five&lt;/LI-CODE&gt;&lt;P&gt;then OR is no longer being treated as a keyword and we get no results back.&amp;nbsp; (we are looking for somefield="one" AND TERM(or) AND TERM(two) )&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now if we looked for somefield with the values of either one or five&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base&amp;gt;
| search somefield = one OR somefield = five&lt;/LI-CODE&gt;&lt;P&gt;we only get one result back as expected. (while "five" shows up in the _raw event, only thirdfield has it as a value)&lt;BR /&gt;&lt;BR /&gt;Now we change back to your other original query (without the extra WHERE), and get back two results:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base&amp;gt;
| search somefield = one OR somefield = two&lt;/LI-CODE&gt;&lt;P&gt;but we got to these two results in a slightly different manner than the original.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;With currently supported versions of Splunk, there is also now an IN operator as well:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base&amp;gt;
| search somefield IN (one, two)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Thats just some of the ins and outs of the "search" command... I'll note that if we move over to the &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/where" target="_self"&gt;where command&lt;/A&gt;&amp;nbsp;that the question becomes rather silly since this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base&amp;gt;
| where somefield = one OR two&lt;/LI-CODE&gt;&lt;P&gt;Is actually a syntax error. (Where doesn't interpret strings on the right hand side automatically as strings but rather as field names... and the field named two cannot be a boolean expression)&lt;BR /&gt;&lt;BR /&gt;If we remove the OR two part... like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base&amp;gt;
| where somefield = one&lt;/LI-CODE&gt;&lt;P&gt;We'll see more about that interpretation change since we get no results back. (There is no field named one therefore somefield cannot equal it). This is actually one of the powerful things about where as opposed to search, making it easier to compare field values to eachother. Let's change this so we get a result back:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base&amp;gt;
| where somefield = otherfield&lt;/LI-CODE&gt;&lt;P&gt;Now we get the "three" result back. If we wanted to look for a field&amp;nbsp;that has a particular string value with the where command, we have to enclose that string in double quotes:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;base&amp;gt;
| where somefield = otherfield OR somefield = "one"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully this gives you a start around a few SPL commands, and helps you understand how meaning can be slightly different with different commands, and answers your question about how with the search command (which is implicit before the first pipe) could be working similarly but differently.&lt;BR /&gt;&lt;BR /&gt;If you haven't yet taken them, I definitely recommend the Fundamentals courses through Splunk Education, and the Search tutorial on Splunk Docs. (It's been a while for me, but I believe these semantics and more should be covered in those courses).&lt;/P&gt;</description>
      <pubDate>Sun, 22 Aug 2021 05:01:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-OR-work-with-strings/m-p/564204#M196527</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2021-08-22T05:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: How does OR work with strings?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-OR-work-with-strings/m-p/564207#M196528</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/171870"&gt;@pm771&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;the two condition you shared are different because:&lt;/P&gt;&lt;P&gt;the first is:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| WHERE (somefield = string1) OR (string2)&lt;/LI-CODE&gt;&lt;P&gt;in other words, you have an OR condition between the condition "somefield=string1" and the search string "string2";&lt;/P&gt;&lt;P&gt;The second one is instead:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| WHERE (somefield = string1) OR (somefield=string2)&lt;/LI-CODE&gt;&lt;P&gt;so you have an OR condition between "somefield=string1" and "somefield=string2".&lt;/P&gt;&lt;P&gt;In other words the second condition is similar but more strong than the first.&lt;/P&gt;&lt;P&gt;The OR condition can work using strings and pairs field=value as you need.&lt;/P&gt;&lt;P&gt;For more infos see at&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/SCS/current/Search/Predicates#Logical_operators" target="_blank"&gt;https://docs.splunk.com/Documentation/SCS/current/Search/Predicates#Logical_operators&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Sun, 22 Aug 2021 08:09:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-OR-work-with-strings/m-p/564207#M196528</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2021-08-22T08:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: How does OR work with strings?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-does-OR-work-with-strings/m-p/564269#M196560</link>
      <description>Excellent explanation &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/56406"&gt;@acharlieh&lt;/a&gt;!&lt;BR /&gt;This "| collect testmode=true " was also nice trick !</description>
      <pubDate>Mon, 23 Aug 2021 07:36:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-does-OR-work-with-strings/m-p/564269#M196560</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2021-08-23T07:36:08Z</dc:date>
    </item>
  </channel>
</rss>

