<?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's the best way to only do a Lookup based on the results of the main search? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659691#M227749</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;What's the best way to only do a Lookup based on the results of the main search?&amp;nbsp; I want to only run this when 2 fields don't match.&amp;nbsp; Pseudo would be&lt;/P&gt;
&lt;P&gt;If field1!=field2&amp;nbsp;THEN | lookup accounts department as field2 OUTPUT&lt;/P&gt;
&lt;P&gt;So like an if then statement most programming languages allow&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Lee&lt;/P&gt;</description>
    <pubDate>Wed, 04 Oct 2023 18:06:31 GMT</pubDate>
    <dc:creator>finchy</dc:creator>
    <dc:date>2023-10-04T18:06:31Z</dc:date>
    <item>
      <title>What's the best way to only do a Lookup based on the results of the main search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659691#M227749</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;What's the best way to only do a Lookup based on the results of the main search?&amp;nbsp; I want to only run this when 2 fields don't match.&amp;nbsp; Pseudo would be&lt;/P&gt;
&lt;P&gt;If field1!=field2&amp;nbsp;THEN | lookup accounts department as field2 OUTPUT&lt;/P&gt;
&lt;P&gt;So like an if then statement most programming languages allow&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Lee&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 18:06:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659691#M227749</guid>
      <dc:creator>finchy</dc:creator>
      <dc:date>2023-10-04T18:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: What's the best way to only do a Lookup based on the results of the main search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659698#M227755</link>
      <description>&lt;P&gt;You cannot do a conditional lookup, but you could do the lookup across all the data and then only conditionally display the data that was looked up.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 18:17:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659698#M227755</guid>
      <dc:creator>fredclown</dc:creator>
      <dc:date>2023-10-04T18:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: What's the best way to only do a Lookup based on the results of the main search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659710#M227760</link>
      <description>&lt;P&gt;Hi, i wanted to avoid doing a lookup if certain conditions are in place if that's not possible will just have to do it which returns the data if it finds any was trying to just save some cpu and time&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 19:23:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659710#M227760</guid>
      <dc:creator>finchy</dc:creator>
      <dc:date>2023-10-04T19:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: What's the best way to only do a Lookup based on the results of the main search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659716#M227764</link>
      <description>&lt;P&gt;How to save CPU will depends on the actual flow of your search. &amp;nbsp;For example, if&amp;nbsp;&lt;SPAN&gt;field1!=&amp;lt;fixed string pattern&amp;gt; is exceedingly rare in a large dataset, you can include the lookup in an append subsearch, like&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;your main search&amp;gt;
| append
  [search &amp;lt;somesearch&amp;gt; field1 != &amp;lt;fixed string pattern&amp;gt;
   | lookup accounts department as field2 OUTPUT]&lt;/LI-CODE&gt;&lt;P&gt;Then &amp;nbsp;manipulate the combined stream to utilize lookup output.&lt;/P&gt;&lt;P&gt;Because field1 != field2 is inapplicable in search command, this technique will not save you index search time. &amp;nbsp;However, if you have a situation where index search is cheap but lookup is exceedingly expensive (it can happen), you can still do it, like&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;your main search&amp;gt;
| append
  [search &amp;lt;same main search&amp;gt;
   | where field1 != field2
   | lookup accounts department as field2 OUTPUT]&lt;/LI-CODE&gt;&lt;P&gt;Alternatively, you are ONLY interested in annotating field2 for which field1 != field2, you can use &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Appendpipe" target="_blank" rel="noopener"&gt;appendpipe&lt;/A&gt; (which is very efficient)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;your main search&amp;gt;
| appendpipe
  [stats count by field1 field2
   | where field1 != field2
   | lookup accounts department as field2 OUTPUT
   | fields - count]&lt;/LI-CODE&gt;&lt;P&gt;In all cases, you will need to massage these annotations back into your final results. &amp;nbsp;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 20:17:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659716#M227764</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-10-04T20:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: What's the best way to only do a Lookup based on the results of the main search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659722#M227765</link>
      <description>&lt;P&gt;You CAN actually do conditional lookup, as long as your lookup is a CSV&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.1.1/SearchReference/ConditionalFunctions#lookup.28.26lt.3Blookup_table.26gt.3B.2C.26lt.3Bjson_object.26gt.3B.2C.26lt.3Bjson_array.26gt.3B.29" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.1.1/SearchReference/ConditionalFunctions#lookup.28.26lt.3Blookup_table.26gt.3B.2C.26lt.3Bjson_object.26gt.3B.2C.26lt.3Bjson_array.26gt.3B.29&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I don't think it's very commonly used, but works well&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;... search...
| eval output=if(field1!=field2, 
          lookup("mylookup.csv", json_object("department", field2), 
                 json_array("output_field1","output_field2")), 
          "{}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;You will get back a field output with a JSON representation of the output fields listed in the JSON array&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 21:11:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659722#M227765</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-10-04T21:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: What's the best way to only do a Lookup based on the results of the main search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659745#M227770</link>
      <description>&lt;P&gt;Nice ref. &amp;nbsp;Thanks,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;! (Looks like something since 8.)&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2023 04:02:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/What-s-the-best-way-to-only-do-a-Lookup-based-on-the-results-of/m-p/659745#M227770</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-10-05T04:02:55Z</dc:date>
    </item>
  </channel>
</rss>

