<?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 What is an efficient way to exclude multiple string criteria from a field in search? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450807#M127658</link>
    <description>&lt;P&gt;Need to exclude field results based on multiple string-matching cirteria (OR):&lt;/P&gt;

&lt;P&gt;-Not equals to any one of several names&lt;BR /&gt;
 -Not ends with "$"&lt;BR /&gt;
 -Only has A-Z, a-z, "-", ".", "_"&lt;BR /&gt;
 -Not contains any one of several names&lt;/P&gt;

&lt;P&gt;Here's my inefficient solution. AdminAccount is the field to query.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where not (AdminAccount = "Joe" or AdminAccount = "Mike" or AdminAccount = "David" or AdminAccount = "Max" or AdminAccount = "Abe" or AdminAccount = "Peter")
| regex AdminAccount != "\$$"
| where NOT match(AdminAccount,"\d+$")
| where NOT match(AdminAccount,"sql|ssoadmin|local service|internal|snapshots|sharepoint")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any way to do this better?   bonus points if you explain why.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Mar 2019 12:50:28 GMT</pubDate>
    <dc:creator>JaoelNameiol</dc:creator>
    <dc:date>2019-03-20T12:50:28Z</dc:date>
    <item>
      <title>What is an efficient way to exclude multiple string criteria from a field in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450807#M127658</link>
      <description>&lt;P&gt;Need to exclude field results based on multiple string-matching cirteria (OR):&lt;/P&gt;

&lt;P&gt;-Not equals to any one of several names&lt;BR /&gt;
 -Not ends with "$"&lt;BR /&gt;
 -Only has A-Z, a-z, "-", ".", "_"&lt;BR /&gt;
 -Not contains any one of several names&lt;/P&gt;

&lt;P&gt;Here's my inefficient solution. AdminAccount is the field to query.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where not (AdminAccount = "Joe" or AdminAccount = "Mike" or AdminAccount = "David" or AdminAccount = "Max" or AdminAccount = "Abe" or AdminAccount = "Peter")
| regex AdminAccount != "\$$"
| where NOT match(AdminAccount,"\d+$")
| where NOT match(AdminAccount,"sql|ssoadmin|local service|internal|snapshots|sharepoint")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any way to do this better?   bonus points if you explain why.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 12:50:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450807#M127658</guid>
      <dc:creator>JaoelNameiol</dc:creator>
      <dc:date>2019-03-20T12:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to exclude multiple string criteria from a field in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450808#M127659</link>
      <description>&lt;P&gt;Where you have a long list of things to exclude, you may consider using a lookup.&lt;/P&gt;

&lt;P&gt;Create a CSV with something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;AdminAccount,exclude
Joe,1
Mike,1
David,1
Max,1
*$,1
sql,1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;etc, etc&lt;/P&gt;

&lt;P&gt;Create a lookup definition for your CSV lookup and set the match type to WILDCARD for the AdminAccount field&lt;/P&gt;

&lt;P&gt;Then run your search, and perform the lookup:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[my search]|lookup exclude_accounts AdminAccount OUTPUT exclude|where exclude!=1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.4/Knowledge/ConfigureCSVlookups"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.4/Knowledge/ConfigureCSVlookups&lt;/A&gt;&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.4/Knowledge/Addfieldmatchingrulestoyourlookupconfiguration"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.4/Knowledge/Addfieldmatchingrulestoyourlookupconfiguration&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:23:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450808#M127659</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2019-03-20T14:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to exclude multiple string criteria from a field in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450809#M127660</link>
      <description>&lt;P&gt;Techinically the whole thing could be one big regex for a single filter like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| regex AdminAccount != "^Joe$|^Mike$|^David$|^Max$|^Abe$|^Peter$|\$$|\d+$|sql|sso|admin|local service|internal|snapshots|sharepoint"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But if readability counts, then maybe switch the first where statement to a &lt;CODE&gt;search&lt;/CODE&gt; (because the IN operator is handy though &lt;CODE&gt;where&lt;/CODE&gt; has something similar) and combine the regex expressions&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| search AdminAccount IN (Joe Mike David Max Peter)
| regex AdminAccount != "\$$|\d+$|sql|sso|admin|local service|internal|snapshots|sharepoint"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:46:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450809#M127660</guid>
      <dc:creator>worshamn</dc:creator>
      <dc:date>2019-03-20T14:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to exclude multiple string criteria from a field in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450810#M127661</link>
      <description>&lt;P&gt;Is a lookup more efficient than the in-search &lt;CODE&gt;where&lt;/CODE&gt; clause?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:50:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450810#M127661</guid>
      <dc:creator>JaoelNameiol</dc:creator>
      <dc:date>2019-03-20T14:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to exclude multiple string criteria from a field in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450811#M127662</link>
      <description>&lt;P&gt;Is one regex faster/more efficient than multiple regex'es?  assuming readability doesn't matter&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 14:51:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450811#M127662</guid>
      <dc:creator>JaoelNameiol</dc:creator>
      <dc:date>2019-03-20T14:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to exclude multiple string criteria from a field in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450812#M127663</link>
      <description>&lt;P&gt;Thats an excellent question - and not one I have ever seen performance comparisons on, however small lookups (&amp;lt;10mb) anecdotally perform very well. &lt;BR /&gt;
The reason is that the data is loaded once into memory, and events are simply matched based on the field value as they are returned, the single where to exclude them is probably as efficient as it gets.&lt;/P&gt;

&lt;P&gt;I would suggest testing both approaches in your environment and use the job inspector to see which one works best for your data and env.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:04:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450812#M127663</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2019-03-20T15:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to exclude multiple string criteria from a field in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450813#M127664</link>
      <description>&lt;P&gt;Well I'm not certain how regex is handled "under the hood" so to speak. I think nickhillscpl depiction of using job inspector is a good idea to test it, but logically a single operation has got to be more efficient then multiple (unless Splunk is combining them) and likely you are passing the load to the regex engine/module/whatever all at once.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:19:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450813#M127664</guid>
      <dc:creator>worshamn</dc:creator>
      <dc:date>2019-03-20T15:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: What is an efficient way to exclude multiple string criteria from a field in search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450814#M127665</link>
      <description>&lt;P&gt;Will do!  thanks&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 15:25:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-is-an-efficient-way-to-exclude-multiple-string-criteria/m-p/450814#M127665</guid>
      <dc:creator>JaoelNameiol</dc:creator>
      <dc:date>2019-03-20T15:25:29Z</dc:date>
    </item>
  </channel>
</rss>

