<?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 Apply Dynamic Regex Matching in a Multisearch Using Values from a Lookup Table? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-Apply-Dynamic-Regex-Matching-in-a-Multisearch-Using/m-p/706064#M238981</link>
    <description>&lt;P&gt;1. Please don't post screenshots - copy-paste your code and results into code blocks or preformatted paragraphs. It makes it easier for everyone and is searchable.&lt;/P&gt;&lt;P&gt;2. You're trying to do something that is generally not supported - you can generate conditions for a search dynamically by means of subsearch, not whole searches. To some extent you could use the map command but it is relatively limited.&lt;/P&gt;&lt;P&gt;3. You can't use multisearch with non-streaming commands (like tstats).&lt;/P&gt;</description>
    <pubDate>Thu, 05 Dec 2024 22:06:37 GMT</pubDate>
    <dc:creator>PickleRick</dc:creator>
    <dc:date>2024-12-05T22:06:37Z</dc:date>
    <item>
      <title>How to Apply Dynamic Regex Matching in a Multisearch Using Values from a Lookup Table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Apply-Dynamic-Regex-Matching-in-a-Multisearch-Using/m-p/706063#M238980</link>
      <description>&lt;P&gt;Hello Splunk experts,&lt;/P&gt;&lt;P&gt;I’m currently trying to create a search using a multisearch command where I need to dynamically apply regex patterns from a lookup file to the Web.url field in a tstats search.&lt;/P&gt;&lt;P&gt;When I use my current approach, it directly adds the regex value as a literal search condition instead of applying it as a regex filter. For example, instead of dynamically matching URLs with the regex, it ends up as if it’s searching for the literal pattern.&lt;/P&gt;&lt;P&gt;I have a lookup that contains fields like url_regex and other filter parameters, and I need to:&lt;/P&gt;&lt;P&gt;1. Dynamically use these regex patterns in the search, so that only URLs matching the regex from the lookup get processed further.&lt;/P&gt;&lt;P&gt;2. Ensure that the logic integrates correctly within a multisearch, where the base search is filtered dynamically based on these values from the lookup.&lt;/P&gt;&lt;P&gt;I’ve shared some screenshots showing the query and the resulting issue, where the regex appears to be used incorrectly. How can I properly use these regex values to match URLs instead of treating them as literal strings?&lt;/P&gt;&lt;P&gt;Search :-&amp;nbsp;&lt;/P&gt;&lt;P&gt;| inputlookup my_lookup_file&lt;BR /&gt;| search Justification="Lookup Instructions"&lt;BR /&gt;| fields url_regex, description&lt;BR /&gt;| fillnull value="*"&lt;BR /&gt;| eval url_regex="Web.url=\"" . url_regex . "\""&lt;BR /&gt;| eval filter="source=\"my_sourcetype\" " . "filter_field=" . " \""&lt;BR /&gt;| eval search="| tstats `summariesonly` prestats=true count from datamodel=Web where sourcetype=\"" . filter . " by Web.url Web.user"&lt;BR /&gt;| stats values(search) as search&lt;BR /&gt;| eval search=multisearch [&lt;BR /&gt;mvjoin(search, " | ")&lt;BR /&gt;] . "&lt;/P&gt;&lt;P&gt;| stats count by search"&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="varma364_1-1733432269799.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/33710i82F995FF931C16FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="varma364_1-1733432269799.png" alt="varma364_1-1733432269799.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As highlighted in the yellow from above I wanted to have the regex matching string instead of the direct regex search from events?&lt;BR /&gt;&lt;BR /&gt;Also, lastly, once the multisearch query generates another search as output, how can I automatically execute that resulting search within my main query?&lt;/P&gt;&lt;P&gt;Any guidance would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 22:54:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Apply-Dynamic-Regex-Matching-in-a-Multisearch-Using/m-p/706063#M238980</guid>
      <dc:creator>varma364</dc:creator>
      <dc:date>2024-12-05T22:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to Apply Dynamic Regex Matching in a Multisearch Using Values from a Lookup Table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Apply-Dynamic-Regex-Matching-in-a-Multisearch-Using/m-p/706064#M238981</link>
      <description>&lt;P&gt;1. Please don't post screenshots - copy-paste your code and results into code blocks or preformatted paragraphs. It makes it easier for everyone and is searchable.&lt;/P&gt;&lt;P&gt;2. You're trying to do something that is generally not supported - you can generate conditions for a search dynamically by means of subsearch, not whole searches. To some extent you could use the map command but it is relatively limited.&lt;/P&gt;&lt;P&gt;3. You can't use multisearch with non-streaming commands (like tstats).&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 22:06:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Apply-Dynamic-Regex-Matching-in-a-Multisearch-Using/m-p/706064#M238981</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-12-05T22:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to Apply Dynamic Regex Matching in a Multisearch Using Values from a Lookup Table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Apply-Dynamic-Regex-Matching-in-a-Multisearch-Using/m-p/706069#M238982</link>
      <description>&lt;P&gt;thank you for the response and I’ve updated the query now.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 22:55:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Apply-Dynamic-Regex-Matching-in-a-Multisearch-Using/m-p/706069#M238982</guid>
      <dc:creator>varma364</dc:creator>
      <dc:date>2024-12-05T22:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to Apply Dynamic Regex Matching in a Multisearch Using Values from a Lookup Table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Apply-Dynamic-Regex-Matching-in-a-Multisearch-Using/m-p/706086#M238988</link>
      <description>&lt;P&gt;Congratulations for heeding&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;'s advice and repost your search in text. &amp;nbsp;Now, let me try to understand this use case. &amp;nbsp;You are trying to use a lookup file to generate SPL code for some other purpose. For that generated code, you wish to use multisearch. &amp;nbsp;But that multisearch has nothing to do with the question itself. &amp;nbsp;Is this accurate?&lt;/P&gt;&lt;P&gt;Then, you want use the returned values from inputlookup as regex to match an &lt;STRONG&gt;indexed field&lt;/STRONG&gt; named Web.url in a tstats command. &amp;nbsp;Is this correct?&lt;/P&gt;&lt;P&gt;Documentation on&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Tstats" target="_blank" rel="noopener"&gt;tstats&lt;/A&gt;&amp;nbsp;will tell you that the&amp;nbsp;&lt;U&gt;where clause&lt;/U&gt;&amp;nbsp;of this command can only accept filters applicable in search command; in fact, only a fraction of these filters. &amp;nbsp;In other words, you cannot use those regex directly in tstats command.&lt;/P&gt;&lt;P&gt;This is not to say that your search goal cannot be achieved. &amp;nbsp;You just need to restructure the subsearches so you can use the &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Where" target="_blank" rel="noopener"&gt;where&lt;/A&gt; command instead of where clause in tstats. &amp;nbsp;But let me first point out that your text illustration of the search not only does not match your screenshot, but also is wrong because url_regex is no longer used in the field filter, therefore no longer used in formulation of the search field. &amp;nbsp;You cannot possibly get the output as your screenshot show. &amp;nbsp;There is another "transcription" error in the last eval command as well because the syntax is incorrect.&lt;/P&gt;&lt;P&gt;Correcting for those errors and simplifying the commands, here is something you can adapt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| inputlookup my_lookup_file where Justification="Lookup Instructions"
| eval search = "[| tstats `summariesonly` prestats=true count from datamodel=Web where sourcetype=\"mysourcetype\" by Web.url Web.user | where match(Web.url, \"" . url_regex . "\")]"
| stats values(search) as search
| eval search = "| multisearch " . mvjoin(search, "
")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose your my_lookup_file contains the following entries (ignoring description field as it is not being used; also ignore fillnull because "*" is not a useful regex to match any URL.)&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;url_regex&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="62.21875px" height="25px"&gt;regex&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="62.21875px" height="25px"&gt;[re]gex&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="62.21875px" height="25px"&gt;^regex&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="62.21875px" height="25px"&gt;regex$&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;the above search will give you&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="100%"&gt;search&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="100%"&gt;&lt;P&gt;&lt;SPAN&gt;| multisearch [| tstats `summariesonly` prestats=true count from datamodel=Web where sourcetype="mysourcetype" by Web.url Web.user | where match(Web.url, "[re]gex")]&lt;BR /&gt;[| tstats `summariesonly` prestats=true count from datamodel=Web where sourcetype="mysourcetype" by Web.url Web.user | where match(Web.url, "^regex")]&lt;BR /&gt;[| tstats `summariesonly` prestats=true count from datamodel=Web where sourcetype="mysourcetype" by Web.url Web.user | where match(Web.url, "regex")]&lt;BR /&gt;[| tstats `summariesonly` prestats=true count from datamodel=Web where sourcetype="mysourcetype" by Web.url Web.user | where match(Web.url, "regex$")]&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Is this what you are looking for?&lt;/P&gt;&lt;P&gt;Here is full emulation to get the above input and output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="url_regex
regex
[re]gex
^regex
regex$"
``` the above emulates
| inputlookup my_lookup_file where Justification="Lookup Instructions"
```
| eval search = "[| tstats `summariesonly` prestats=true count from datamodel=Web where sourcetype=\"mysourcetype\" by Web.url Web.user | where match(Web.url, \"" . url_regex . "\")]"
| stats values(search) as search
| eval search = "| multisearch " . mvjoin(search, "
")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Play with it and compare with your real lookup.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2024 06:13:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Apply-Dynamic-Regex-Matching-in-a-Multisearch-Using/m-p/706086#M238988</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-12-06T06:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to Apply Dynamic Regex Matching in a Multisearch Using Values from a Lookup Table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Apply-Dynamic-Regex-Matching-in-a-Multisearch-Using/m-p/706112#M238990</link>
      <description>&lt;P&gt;OK. Now let's back up a little.&lt;/P&gt;&lt;P&gt;Explain in your own words, without using SPL what business problem you're trying to solve here. What are you trying to achieve?&lt;/P&gt;&lt;P&gt;You're clearly trying to "implement non-SPL thing in SPL" which is usually not a very good idea. Or at least not a very efficient one. And same things can often be achieved in a different way.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2024 08:53:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Apply-Dynamic-Regex-Matching-in-a-Multisearch-Using/m-p/706112#M238990</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-12-06T08:53:59Z</dc:date>
    </item>
  </channel>
</rss>

