<?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: Most efficient way to filter results matching a list of values in either of two(+) fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Most-efficient-way-to-filter-results-matching-a-list-of-values/m-p/586721#M204372</link>
    <description>&lt;P&gt;Thanks for posing this question. &amp;nbsp;Boy, do I have eyesore problem of my own:-) &amp;nbsp;One workaround is to use &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Usesearchmacros" target="_blank" rel="noopener"&gt;macro&lt;/A&gt;. &amp;nbsp;You can put any literal in a macro, such as "&lt;SPAN&gt;(value1, value2, value3, value4, value5, ...)" so your search becomes&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;index=my_index ...etc... (field1 IN `mymacro` OR field2 IN&amp;nbsp;`mymacro`)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You can even make "IN&amp;nbsp;(value1, value2, value3, value4, value5, ...)" your macro so the search becomes&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;index=my_index ...etc... (field1 `myinmacro` OR field2 `myinmacro`)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;With this method, you cannot parameterize or the eyesore returns. (Suffice to say, macro is not a cure-all. &amp;nbsp;Hence my own eyesores:-)&lt;/P&gt;&lt;P&gt;OT: A classic solution to this type of eyesore is iteration. &amp;nbsp;In non-search languages, iteration doesn't compromise efficiency much. &amp;nbsp;The following SPL iteration will give you the same result, but at terrible cost.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=my_index ...etc...
| foreach field1 field2
  [eval good=mvmap(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, if(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; IN (value1, value2, value3, value4, value5, ...), "good", good))]
| where isnotnull(good)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 26 Feb 2022 20:28:30 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2022-02-26T20:28:30Z</dc:date>
    <item>
      <title>Most efficient way to filter results matching a list of values in either of two(+) fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-efficient-way-to-filter-results-matching-a-list-of-values/m-p/586675#M204351</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Hello everyone. I'm trying to find the most efficient way to filter results for a list of values that may have a match within two (or more) distinct fields. Say, a list of IP addresses that can match either the source or destination fields. I'm almost certain this question has been answered in the past but I couldn't find the correct wording to find the answer (am braindead atm), so here I am.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;To help filter some potential answers to my request, I do know that I can do something like:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;index=my_index ...etc... (field1 IN (value1, value2, value3, value4, value5, ...) OR field2 IN&amp;nbsp;(value1, value2, value3, value4, value5, ...))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;However, what I am attempting to do is make this query more "efficient". Or, perhaps just less of an eye-sore. Provided a list of 10+ values to filter for, it's easy to see how this query can get out of hand at least visually. Here is an example query I intuitively tried that should help illustrate what I'm looking for:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;index=my_index ...etc... (field1 OR field2 IN (value1, value2, value3, value4, value5, ...))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Splunk Pros, please help: What am I overlooking/overthinking? Or is my first example the best (or most "efficient") way to go about this?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Thanks so much!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Feb 2022 22:39:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-efficient-way-to-filter-results-matching-a-list-of-values/m-p/586675#M204351</guid>
      <dc:creator>hackwerks</dc:creator>
      <dc:date>2022-02-25T22:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to filter results matching a list of values in either of two(+) fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-efficient-way-to-filter-results-matching-a-list-of-values/m-p/586697#M204358</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/243421"&gt;@hackwerks&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;maybe this could be a good workaround:&lt;/P&gt;&lt;P&gt;put the values in a lookup (called e.g. patterns.csv, with one column called e.g. "pattern") and run something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=my_index [ | inputlookup patterns.csv | rename pattern AS query | fields query ]
| ...&lt;/LI-CODE&gt;&lt;P&gt;in this way, you run a full text search, using the values in the lookup, on you index.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Feb 2022 07:15:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-efficient-way-to-filter-results-matching-a-list-of-values/m-p/586697#M204358</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-02-26T07:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to filter results matching a list of values in either of two(+) fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-efficient-way-to-filter-results-matching-a-list-of-values/m-p/586721#M204372</link>
      <description>&lt;P&gt;Thanks for posing this question. &amp;nbsp;Boy, do I have eyesore problem of my own:-) &amp;nbsp;One workaround is to use &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Usesearchmacros" target="_blank" rel="noopener"&gt;macro&lt;/A&gt;. &amp;nbsp;You can put any literal in a macro, such as "&lt;SPAN&gt;(value1, value2, value3, value4, value5, ...)" so your search becomes&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;index=my_index ...etc... (field1 IN `mymacro` OR field2 IN&amp;nbsp;`mymacro`)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You can even make "IN&amp;nbsp;(value1, value2, value3, value4, value5, ...)" your macro so the search becomes&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;index=my_index ...etc... (field1 `myinmacro` OR field2 `myinmacro`)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;With this method, you cannot parameterize or the eyesore returns. (Suffice to say, macro is not a cure-all. &amp;nbsp;Hence my own eyesores:-)&lt;/P&gt;&lt;P&gt;OT: A classic solution to this type of eyesore is iteration. &amp;nbsp;In non-search languages, iteration doesn't compromise efficiency much. &amp;nbsp;The following SPL iteration will give you the same result, but at terrible cost.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=my_index ...etc...
| foreach field1 field2
  [eval good=mvmap(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, if(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; IN (value1, value2, value3, value4, value5, ...), "good", good))]
| where isnotnull(good)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Feb 2022 20:28:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-efficient-way-to-filter-results-matching-a-list-of-values/m-p/586721#M204372</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-02-26T20:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Most efficient way to filter results matching a list of values in either of two(+) fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Most-efficient-way-to-filter-results-matching-a-list-of-values/m-p/587087#M204468</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/161352"&gt;@gcusello&lt;/a&gt;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;- Excellent ideas. I'm clearly too new to the platform to be aware of those options. Thank you both very, very much for your prompt responses!&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 20:20:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Most-efficient-way-to-filter-results-matching-a-list-of-values/m-p/587087#M204468</guid>
      <dc:creator>hackwerks</dc:creator>
      <dc:date>2022-03-01T20:20:07Z</dc:date>
    </item>
  </channel>
</rss>

