<?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: Why is lookup command not giving result as expected? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639890#M221735</link>
    <description>&lt;P&gt;Is it possible that Base is coming from your events in the index?&lt;/P&gt;&lt;P&gt;Please show your full SPL where this is failing.&lt;/P&gt;</description>
    <pubDate>Thu, 13 Apr 2023 22:41:34 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2023-04-13T22:41:34Z</dc:date>
    <item>
      <title>Why is lookup command not giving result as expected?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639823#M221718</link>
      <description>&lt;P&gt;Hi All, I am facing some issue in using lookup command. Need your suggestions here please..&lt;/P&gt;
&lt;P&gt;I have a lookup file as below: In that I have same host under different base.&lt;/P&gt;
&lt;TABLE border="0" width="192" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64" height="19"&gt;Base&lt;/TD&gt;
&lt;TD width="64"&gt;Host&lt;/TD&gt;
&lt;TD width="64"&gt;Category&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;X&lt;/TD&gt;
&lt;TD&gt;device1&lt;/TD&gt;
&lt;TD&gt;Lin&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;&lt;STRONG&gt;X&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;device2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;Win&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;X&lt;/TD&gt;
&lt;TD&gt;device3&lt;/TD&gt;
&lt;TD&gt;Lin&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;&lt;STRONG&gt;M&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;device2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;Lin&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;M&lt;/TD&gt;
&lt;TD&gt;device14&lt;/TD&gt;
&lt;TD&gt;Win&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;M&lt;/TD&gt;
&lt;TD&gt;device15&lt;/TD&gt;
&lt;TD&gt;Win&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;I need to compare the hosts (&lt;STRONG&gt;from Base 'M'&lt;/STRONG&gt;) with hostname reporting under particular index and need to get the list of matching hosts.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Query&lt;/STRONG&gt;:&lt;BR /&gt;index=indexA&lt;BR /&gt;| lookup lookupfilename Host as hostname OUTPUTNEW Base,Category&lt;BR /&gt;| fields hostname,Base,Category&lt;BR /&gt;| stats count by hostname,Base,Category&lt;BR /&gt;| where Base="M"&lt;/P&gt;
&lt;P&gt;As per my lookup file, I should get output as below (considering device2 &amp;amp; device14 available in splunk index)&lt;/P&gt;
&lt;TABLE width="198"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;hostname&lt;/TD&gt;
&lt;TD width="57"&gt;Base&lt;/TD&gt;
&lt;TD width="64"&gt;Category&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;device2&lt;/TD&gt;
&lt;TD&gt;M&lt;/TD&gt;
&lt;TD&gt;Lin&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;device14&lt;/TD&gt;
&lt;TD&gt;M&lt;/TD&gt;
&lt;TD&gt;Win&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;But I am getting 2 entries under device2 as below (&lt;STRONG&gt;entry under category "Win" is incorrect&lt;/STRONG&gt;) :&lt;/P&gt;
&lt;TABLE width="198"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;hostname&lt;/TD&gt;
&lt;TD width="57"&gt;Base&lt;/TD&gt;
&lt;TD width="64"&gt;Category&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;STRONG&gt;device2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;M&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;Win&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;device2&lt;/TD&gt;
&lt;TD&gt;M&lt;/TD&gt;
&lt;TD&gt;Lin&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;device14&lt;/TD&gt;
&lt;TD&gt;M&lt;/TD&gt;
&lt;TD&gt;Win&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Please help me on the query that I have framed. thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 16:25:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639823#M221718</guid>
      <dc:creator>RanjiRaje</dc:creator>
      <dc:date>2023-04-13T16:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why is lookup command not giving result as expected?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639828#M221719</link>
      <description>&lt;LI-CODE lang="markup"&gt;| eval Base="M"
| lookup hosts.csv Host as hostname Base OUTPUTNEW Category
| fields hostname,Base,Category
| stats count by hostname,Base,Category&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 13 Apr 2023 16:28:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639828#M221719</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-04-13T16:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: Why is lookup command not giving result as expected?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639832#M221720</link>
      <description>&lt;P&gt;Hi , thanks for your suggestion. I tried the way u said. but it is also not providing the result as expected&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 16:39:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639832#M221720</guid>
      <dc:creator>RanjiRaje</dc:creator>
      <dc:date>2023-04-13T16:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Why is lookup command not giving result as expected?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639834#M221722</link>
      <description>&lt;P&gt;OK that seems unlikely as setting the Base to "M" and including in the lookup would mean that only rows with Base="M" and Host=hostname would be returned.&lt;/P&gt;&lt;P&gt;What other rows are you getting back from the lookup (that you weren't expecting?)?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 16:48:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639834#M221722</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-04-13T16:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Why is lookup command not giving result as expected?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639836#M221723</link>
      <description>&lt;P&gt;The other &lt;STRONG&gt;Base&lt;/STRONG&gt; which has the same hostname is getting included in my result which is incorrect.&lt;/P&gt;&lt;P&gt;in my example:&lt;/P&gt;&lt;P&gt;Host "&lt;STRONG&gt;device2&lt;/STRONG&gt; " is present in both the Base (M, X). As per my where condition, I should get only &lt;STRONG&gt;Base 'M'&lt;/STRONG&gt; with &lt;STRONG&gt;Category 'Lin'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;But I am getting 2 entries for device2 (by referring both the Base) with &lt;STRONG&gt;Category 'Lin' and 'Win'&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 17:03:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639836#M221723</guid>
      <dc:creator>RanjiRaje</dc:creator>
      <dc:date>2023-04-13T17:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Why is lookup command not giving result as expected?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639875#M221733</link>
      <description>&lt;P&gt;Is it possible that your lookup table has data entry error? &amp;nbsp;Use this as a test:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| lookup lookupfilename
| stats count by Host Base Category
| rename Host as hostname 
| where Base == "M" AND hostname == "device2"&lt;/LI-CODE&gt;&lt;P&gt;Does this give you the desired results?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 20:21:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639875#M221733</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-04-13T20:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: Why is lookup command not giving result as expected?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639890#M221735</link>
      <description>&lt;P&gt;Is it possible that Base is coming from your events in the index?&lt;/P&gt;&lt;P&gt;Please show your full SPL where this is failing.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 22:41:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/639890#M221735</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-04-13T22:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why is lookup command not giving result as expected?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/640108#M221812</link>
      <description>&lt;P&gt;The problem is that your lookup will create TWO multivalued fields: "Base" and "Category" and unless you entangle them row-wise they association will be lost.&amp;nbsp; You can do this 2 ways.&amp;nbsp; You can merge the 2 fields into a single field called "Base_and_Category" and then do filter/split/mevexpand, but this is probably more trouble than it is worth.&amp;nbsp; The other option is to lookup each (potentially) multivalue field separately and filter/stats/mvexpand before doing the other field.&amp;nbsp; Try this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;|makeresults&lt;BR /&gt;| eval _raw="&lt;BR /&gt;Base Host Category&lt;BR /&gt;X device1 Lin&lt;BR /&gt;X device2 Win&lt;BR /&gt;X device3 Lin&lt;BR /&gt;M device2 Lin&lt;BR /&gt;M device14 Win&lt;BR /&gt;M device15 Win"&lt;BR /&gt;| multikv forceheader=1&lt;BR /&gt;| fields - _* linecount&lt;BR /&gt;| outputlookup eraseme.csv&lt;BR /&gt;| stats count BY Host&lt;BR /&gt;| rename Host AS hostname&lt;/P&gt;&lt;P&gt;| rename COMMENT AS "Everything above is setup; everything below is your answer"&lt;/P&gt;&lt;P&gt;| lookup eraseme.csv Host AS hostname OUTPUT Base&lt;BR /&gt;| stats count BY hostname Base&lt;BR /&gt;| search Base="M"&lt;BR /&gt;| lookup eraseme.csv Host AS hostname Base OUTPUT Category&lt;/P&gt;</description>
      <pubDate>Sun, 16 Apr 2023 02:11:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-lookup-command-not-giving-result-as-expected/m-p/640108#M221812</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2023-04-16T02:11:03Z</dc:date>
    </item>
  </channel>
</rss>

