<?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 can I do a lookup where a field does not exist? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345116#M102253</link>
    <description>&lt;P&gt;Update: I changed the eval that determines the TRUE/FALSE to a calculated field.  That way I can just do this:&lt;/P&gt;

&lt;P&gt;| eval Summary=if(like(expirationUpdated,"TRUE"),"Key Expiration Updated",Summary)&lt;/P&gt;

&lt;P&gt;instead of needing two evals&lt;/P&gt;</description>
    <pubDate>Mon, 18 Dec 2017 18:40:07 GMT</pubDate>
    <dc:creator>jdoll1</dc:creator>
    <dc:date>2017-12-18T18:40:07Z</dc:date>
    <item>
      <title>How can I do a lookup where a field does not exist?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345106#M102243</link>
      <description>&lt;P&gt;I'm trying to create a search that will do a lookup against a control file, and show me events where the events meet criteria in the control file and return the "Summary" field of that file.  The problem is that I have two criteria that are similar, but for one I expect a value (any value) in Field5, and the other I expect Field5 to not exist.  How can I do this?&lt;/P&gt;

&lt;P&gt;My base search&lt;/P&gt;

&lt;P&gt;sourcetype=mysource&lt;BR /&gt;
    [ inputlookup mycsv.csv &lt;BR /&gt;
    | fields field1,field2,field3,field4,field5 ] &lt;BR /&gt;
| lookup mycsv.csv field1&lt;BR /&gt;
| table _time,summary&lt;/P&gt;

&lt;P&gt;in my CSV i have the following sample data:&lt;BR /&gt;
Summary   Field1   Field2    Field3   Field4   Field5&lt;BR /&gt;
Event1        foo1      foo2       foo3      foo4     *&lt;BR /&gt;
Event2        foo1      foo2       foo3      foo4    (blank entry in the csv)&lt;/P&gt;

&lt;P&gt;CSV contiains additional rows with other criteria for the fields&lt;/P&gt;

&lt;P&gt;My results come back with the Summary field showing Event1 and Event2 for both events that match fields1-4, regardless of Field5..&lt;/P&gt;

&lt;P&gt;if I do a search for &lt;BR /&gt;
sourcetype=mysource field1=foo1 field2=foo2 field3=foo3 field4=foo4 NOT field5= *&lt;/P&gt;

&lt;P&gt;or&lt;/P&gt;

&lt;P&gt;sourcetype=mysource field1=foo1 field2=foo2 field3=foo3 field4=foo4 field5= *&lt;/P&gt;

&lt;P&gt;I get the expected results individually - how can I combine this in my lookup file?  &lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 20:12:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345106#M102243</guid>
      <dc:creator>jdoll1</dc:creator>
      <dc:date>2017-12-13T20:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a lookup where a field does not exist?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345107#M102244</link>
      <description>&lt;P&gt;@jdoll1&lt;/P&gt;

&lt;P&gt;try this,&lt;/P&gt;

&lt;P&gt;sourcetype=mysource&lt;BR /&gt;
[ inputlookup mycsv.csv&lt;BR /&gt;
| fields field1,field2,field3,field4,field5 ]&lt;BR /&gt;
| lookup mycsv.csv field1&lt;BR /&gt;
| eval resultF5=if(field5!=" ", "field5 with value","field5 without value") &lt;BR /&gt;
| table _time,summary, resultF5&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 21:02:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345107#M102244</guid>
      <dc:creator>sbbadri</dc:creator>
      <dc:date>2017-12-13T21:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a lookup where a field does not exist?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345108#M102245</link>
      <description>&lt;P&gt;They all come back with "field5 without value".  I tried both the positive and negative matches, tried using &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;isNull and = *
NOT = *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 21:11:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345108#M102245</guid>
      <dc:creator>jdoll1</dc:creator>
      <dc:date>2017-12-13T21:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a lookup where a field does not exist?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345109#M102246</link>
      <description>&lt;P&gt;going off of @sbbadri 's solution:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=mysource
[ inputlookup mycsv.csv
| table field1,field2,field3,field4,field5|format ]
| lookup mycsv.csv field1
| eval resultF5=if(isnotnull(field5), "field5 with value","field5 without value") 
| table _time,summary, resultF5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;if you have any sample data from &lt;EM&gt;mysource&lt;/EM&gt; and &lt;EM&gt;mycsv&lt;/EM&gt; and what the expected output should be, that might be more helpful if the above doesn't work.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 21:34:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345109#M102246</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-12-13T21:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a lookup where a field does not exist?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345110#M102247</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=mysource
 [ inputlookup mycsv.csv 
 | fields field1,field2,field3,field4,field5 
 | format | rex field=search mode=sed "s/(field4\=\"[^\"]+\"\s+)\)/\1 AND NOT field5=*)/g" ] 
| lookup mycsv.csv field1
| table _time,summary
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When field5 is blank/null on 2nd rows, Splunk generates following condition from subsearch:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;( ( field1="A1" AND field2="B1" AND field3="C1" AND field4="D1" AND field5="E1" ) OR ( field1="A2" AND field2="B2" AND field3="C2" AND field4="D2" ) ) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Above search basically looks for missing field5 expression (after &lt;CODE&gt;field4="xx"&lt;/CODE&gt; , you get closing bracket), and adds a &lt;CODE&gt;AND field5=*&lt;/CODE&gt; there. so that the condition becomes:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;( ( field1="A1" AND field2="B1" AND field3="C1" AND field4="D1" AND field5="E1" ) OR ( field1="A2" AND field2="B2" AND field3="C2" AND field4="D2" AND NOT field5=*) ) 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 22:22:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345110#M102247</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-13T22:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a lookup where a field does not exist?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345111#M102248</link>
      <description>&lt;P&gt;Try this - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=mysource
    [ inputlookup mycsv.csv 
    | table field1,field2,field3,field4 ]
| lookup mycsv.csv field1 field2 field3 field4 OUTPUT field5 as field5_Flag
| where (isnotnull(field5) AND isnotnull(field5_Flag))
    OR  (isnull(field5) AND (isnull(field5_Flag) OR field5_Flag=""))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That will select records that match the first four, and then test the fifth.  &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Personally, I would change field5 in the csv to a flag with "Some", "None" , or "Any"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=mysource
    [ inputlookup mycsv.csv 
    | table field1,field2,field3,field4 ]
| lookup mycsv.csv field1 field2 field3 field4 OUTPUT field5_Flag
| where (isnotnull(field5) AND (field5_Flag="Some" OR field5_Flag="Any"))
    OR  (isnull(field5) AND (field5_Flag="None" OR field5_Flag="Any"))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Dec 2017 22:36:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345111#M102248</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-12-13T22:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a lookup where a field does not exist?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345112#M102249</link>
      <description>&lt;P&gt;Doesn't seem to work.  For some reason, i'm not getting the field5_flag in my resulting events, therefore the where is not working at all.&lt;/P&gt;

&lt;P&gt;I've tried stripping it down to before the where, but the flag field just doesn't come back&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 16:04:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345112#M102249</guid>
      <dc:creator>jdoll1</dc:creator>
      <dc:date>2017-12-14T16:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a lookup where a field does not exist?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345113#M102250</link>
      <description>&lt;P&gt;This search seems to just ignore all events where the first four match...and gives me nothing.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 17:32:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345113#M102250</guid>
      <dc:creator>jdoll1</dc:creator>
      <dc:date>2017-12-14T17:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a lookup where a field does not exist?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345114#M102251</link>
      <description>&lt;P&gt;Ok. Can you post the normalizedSearch value from the Inspect Job for it? (the subsearch would expand and seeing that will help fix the formatting).&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2017 17:41:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345114#M102251</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-12-14T17:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a lookup where a field does not exist?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345115#M102252</link>
      <description>&lt;P&gt;Sorry, the data is security data, so can't really provide samples.  This didn't work exactly either, but I think i've got it now, based off this answer.  I really don't like it, and i'm sure that there is a much better/cleaner way to do this.&lt;/P&gt;

&lt;P&gt;I've changed around my format of the CSV a little, and have pulled the field5 out all together, and I also pulled the second "matching" line out.  so my sample CSV looks like this now:&lt;/P&gt;

&lt;P&gt;Summary Field1 Field2 Field3 Field4&lt;BR /&gt;
Event1        foo1   foo2   foo3   foo4&lt;BR /&gt;
Event2        bar1  bar2   bar3   bar4&lt;BR /&gt;
etc&lt;/P&gt;

&lt;P&gt;my search is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=mysource
    [ inputlookup mycsv.csv 
    | fields field1,field2,field3,field4 ] 
| eval field5Exists=if(isnotnull(field5),"TRUE","FALSE")
| lookup mycsv.csv field1
| eval Summary=if(like(field5Exists,"TRUE"),"Event That is no longer in CSV","Event1")
| table _time,Summary
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Dec 2017 18:18:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345115#M102252</guid>
      <dc:creator>jdoll1</dc:creator>
      <dc:date>2017-12-14T18:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: How can I do a lookup where a field does not exist?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345116#M102253</link>
      <description>&lt;P&gt;Update: I changed the eval that determines the TRUE/FALSE to a calculated field.  That way I can just do this:&lt;/P&gt;

&lt;P&gt;| eval Summary=if(like(expirationUpdated,"TRUE"),"Key Expiration Updated",Summary)&lt;/P&gt;

&lt;P&gt;instead of needing two evals&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2017 18:40:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-do-a-lookup-where-a-field-does-not-exist/m-p/345116#M102253</guid>
      <dc:creator>jdoll1</dc:creator>
      <dc:date>2017-12-18T18:40:07Z</dc:date>
    </item>
  </channel>
</rss>

