<?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: Splunk Lookup in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658160#M227353</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;So my first SPL, it gets me the URLs I'm looking for but doesn't list the URLs (in the lookup) that don't get any results.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The parenthesis "&lt;SPAN&gt;(&lt;STRONG&gt;in the lookup&lt;/STRONG&gt;)" is key here. &amp;nbsp;My first reading of "only counting the matches, i need the URLs that don't exist to count 0" took it to mean URLs in the index that didn't have a match. &amp;nbsp;This new description makes perfect sense. &amp;nbsp;And your search is more efficient.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="web_index" 
    [| inputlookup URLs.csv 
    |  fields kurl 
    |  rename kurl as url]
| stats count by url
| append
    [inputlookup URLs.csv
    | fields kurl
    | rename kurl AS url]
| stats sum(count) as count by url
| fillnull count ``` or you can omit this and leave nonexistent to show null ```​&lt;/LI-CODE&gt;&lt;P&gt;Alternatively, you can do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="web_index" 
    [| inputlookup URLs.csv 
    |  fields kurl 
    |  rename kurl as url]
| append
    [inputlookup URLs.csv
    | fields kurl
    | rename kurl AS url]
| eval match = if(isnull(match), 0, 1)
| stats sum(match) as count by url&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Sep 2023 16:17:17 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2023-09-20T16:17:17Z</dc:date>
    <item>
      <title>How to count or match fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/657932#M227253</link>
      <description>&lt;P&gt;I have a CSV of URLs I need to search against my proxy index (the url field), I want to be able to do a count or match of the URLs.&lt;BR /&gt;my csv looks like this (with the header of the column called kurl)&lt;BR /&gt;kurl&lt;BR /&gt;splunk.com&lt;BR /&gt;youtube.com&lt;BR /&gt;google.com&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So far, I have this SPL but it's only counting the matches, i need the URLs that don't exist to count 0&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;index="web_index" 
    [| inputlookup URLs.csv 
    |  fields kurl 
    |  rename kurl as url]
| stats count by url&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;</description>
      <pubDate>Wed, 20 Sep 2023 18:39:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/657932#M227253</guid>
      <dc:creator>David_Arnold</dc:creator>
      <dc:date>2023-09-20T18:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658061#M227305</link>
      <description>&lt;P&gt;You selected &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Lookup" target="_blank" rel="noopener"&gt;lookup&lt;/A&gt; as label, but are using inputlookup&lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;. &amp;nbsp;You would have the answer if you stick to lookup.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="web_index" 
| lookup URLs.csv kurl as url output kurl as match
| eval match = if(isnull(match), 0, 1)
| stats sum(match) as count by url&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 00:05:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658061#M227305</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-09-20T00:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658071#M227312</link>
      <description>&lt;P&gt;That also returned every url not on my lookup.&amp;nbsp; I guess I could just take the hits and do a duplicate compare in excel but it'd be nice to see it all in splunk.&lt;/P&gt;&lt;P&gt;Yeah, sorry about the tag I wasn't paying attention.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 01:37:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658071#M227312</guid>
      <dc:creator>David_Arnold</dc:creator>
      <dc:date>2023-09-20T01:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658078#M227315</link>
      <description>&lt;P&gt;Maybe you can explain the requirement further? &amp;nbsp;You said of your original SPL "&lt;SPAN&gt;it's only counting the matches, i need the URLs that don't exist to count 0." &amp;nbsp;So, I thought you would want every url not with a match. &amp;nbsp;Could you mock up some data in web_index and explain why the output doesn't meet the requirements?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is my emulation&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| fields - _time
| eval url = mvappend("google.com", "foo.com", "bar.com", "google.com")
| mvexpand url
``` the above emulates index="web_index" ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;url&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;google.com&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;foo.com&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;bar.com&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;google.com&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Using the exact mock lookup you give, my search will give&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;url&lt;/TD&gt;&lt;TD&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;bar.com&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;foo.com&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;google.com&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Is this not what you want, bar.com and foo.com count to 0?&lt;/P&gt;&lt;P&gt;Below is the full example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| fields - _time
| eval url = mvappend("google.com", "foo.com", "bar.com", "google.com")
| mvexpand url
``` the above emulates index="web_index" ```
| lookup URLs.csv kurl as url output kurl as match
| eval match = if(isnull(match), 0, 1)
| stats sum(match) as count by url&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 05:04:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658078#M227315</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-09-20T05:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658082#M227318</link>
      <description>&lt;P&gt;So my first SPL, it gets me the URLs I'm looking for but doesn't list the URLs (in the lookup) that don't get any results.&lt;BR /&gt;So to break it down, say my csv has 120 URLs and I would like to know what my users are hitting and not hitting, when i run my first example search I'm getting 43 results back, but I also want to know what are the URLs (out of the 120) not hitting? Or should I create a search only telling me the URLs that don't match in the index?&lt;BR /&gt;&lt;BR /&gt;Whilst that example does make sense, in the stats table I get all these other URLs that aren't even in my lookup list that I care about.&amp;nbsp; So I go from expecting 120 results to (18,000).&lt;BR /&gt;&lt;BR /&gt;Does that make more sense?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 05:48:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658082#M227318</guid>
      <dc:creator>David_Arnold</dc:creator>
      <dc:date>2023-09-20T05:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658160#M227353</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;So my first SPL, it gets me the URLs I'm looking for but doesn't list the URLs (in the lookup) that don't get any results.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The parenthesis "&lt;SPAN&gt;(&lt;STRONG&gt;in the lookup&lt;/STRONG&gt;)" is key here. &amp;nbsp;My first reading of "only counting the matches, i need the URLs that don't exist to count 0" took it to mean URLs in the index that didn't have a match. &amp;nbsp;This new description makes perfect sense. &amp;nbsp;And your search is more efficient.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="web_index" 
    [| inputlookup URLs.csv 
    |  fields kurl 
    |  rename kurl as url]
| stats count by url
| append
    [inputlookup URLs.csv
    | fields kurl
    | rename kurl AS url]
| stats sum(count) as count by url
| fillnull count ``` or you can omit this and leave nonexistent to show null ```​&lt;/LI-CODE&gt;&lt;P&gt;Alternatively, you can do&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="web_index" 
    [| inputlookup URLs.csv 
    |  fields kurl 
    |  rename kurl as url]
| append
    [inputlookup URLs.csv
    | fields kurl
    | rename kurl AS url]
| eval match = if(isnull(match), 0, 1)
| stats sum(match) as count by url&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 16:17:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658160#M227353</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-09-20T16:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658194#M227365</link>
      <description>&lt;P&gt;Yeah it still doesn't mark the URLs in my list that don't exist in the index as 0.&lt;/P&gt;&lt;P&gt;I'll just accept your solution though, thanks for your help &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 22:08:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658194#M227365</guid>
      <dc:creator>David_Arnold</dc:creator>
      <dc:date>2023-09-20T22:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658196#M227367</link>
      <description>&lt;P&gt;Actually, I made a mistake when I emulate data. (I had a spurious "match" field in emulation which your index subsearch will not give.) &amp;nbsp; Here is the correct solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="web_index" 
    [| inputlookup URLs.csv 
    |  fields kurl 
    |  rename kurl as url]
| append
    [inputlookup URLs.csv
    | fields kurl]
| eval match = if(isnull(url), 0, 1)
| eval url = coalesce(url, kurl)
| stats sum(match) as count by url&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the corrected emulation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval url = mvappend("google.com", "foo.com", "bar.com", "google.com")
| eval index = "web_index"
| mvexpand url
| search * 
    [ inputlookup URLs.csv 
    |  fields kurl 
    |  rename kurl as url]
``` the above emulates
index="web_index" 
    [| inputlookup URLs.csv 
    |  fields kurl 
    |  rename kurl as url]
```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This gives&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;_time&lt;/TD&gt;&lt;TD&gt;index&lt;/TD&gt;&lt;TD&gt;url&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2023-09-20 16:20:05&lt;/TD&gt;&lt;TD&gt;web_index&lt;/TD&gt;&lt;TD&gt;google.com&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2023-09-20 16:20:05&lt;/TD&gt;&lt;TD&gt;web_index&lt;/TD&gt;&lt;TD&gt;google.com&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;(If your results do not meet the requirement, it would be useful to compare real data with emulation.) &amp;nbsp;Combined simulation is then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval url = mvappend("google.com", "foo.com", "bar.com", "google.com")
| mvexpand url
| lookup URLs.csv kurl as url output kurl as match
| where isnotnull(match)
| fields - match
``` the above emulates
index="web_index" 
    [| inputlookup URLs.csv 
    |  fields kurl 
    |  rename kurl as url]
```
| append
    [inputlookup URLs.csv
    | fields kurl]
| eval match = if(isnull(url), 0, 1)
| eval url = coalesce(url, kurl)
| stats sum(match) as count by url&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;url&lt;/TD&gt;&lt;TD&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;google.com&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;splunk.com&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;youtube.com&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I still don't understand why the first option (stats before append) would not give you the correct output. &amp;nbsp;Here's my full emulation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval url = mvappend("google.com", "foo.com", "bar.com", "google.com")
| mvexpand url
| lookup URLs.csv kurl as url output kurl as match
| where isnotnull(match)
| fields - match
``` the above emulates
index="web_index" 
    [| inputlookup URLs.csv 
    |  fields kurl 
    |  rename kurl as url]
```
| stats count by url
| append
    [inputlookup URLs.csv
    | fields kurl
    | rename kurl AS url]
| stats sum(count) as count by url
| fillnull count ``` or you can omit this and leave nonexistent to show null ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again&amp;nbsp;It would help if you can run data part of emulation and let me know the difference with real data.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 23:36:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658196#M227367</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-09-20T23:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658197#M227368</link>
      <description>&lt;P&gt;THIS WORKS!!!!!!!!!!&lt;BR /&gt;Thanks so much!!!!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 23:46:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-or-match-fields/m-p/658197#M227368</guid>
      <dc:creator>David_Arnold</dc:creator>
      <dc:date>2023-09-20T23:46:33Z</dc:date>
    </item>
  </channel>
</rss>

