<?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 using map and if/isnull but missing fields in base is causing failure in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/using-map-and-if-isnull-but-missing-fields-in-base-is-causing/m-p/443528#M125822</link>
    <description>&lt;P&gt;hi could someone please help me out here. been stuck with a problem. we have multiple existing queries in our environment. i am creating a sort of universal macro to work with the current queries.&lt;/P&gt;

&lt;P&gt;the problem is, there are some fields which exists in some of the base queries but doesnt exist in another. how do i do a map in that macro with and if/isnull even with the missing fields.&lt;/P&gt;

&lt;P&gt;Example&lt;/P&gt;

&lt;P&gt;base search1 below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval field1="abc"
| eval field2="def"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;base search2 below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval field1="abc"
| eval field2="def"
| eval field3="opq"
| eval field4="rst"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;macro below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| map [search index=test1...
| eval field1=if(isnull("$field1$"),"","$field1$")
| eval field2=if(isnull("$field2$"),"","$field2$")
| eval field3=if(isnull("$field3$"),"","$field3$")
| eval field4=if(isnull("$field4$"),"","$field4$")]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;so the thing is, map will fail for base search1 but working on base search2. is there a way to fix this? there multiple fields in the base query.&lt;/P&gt;

&lt;P&gt;thanks!&lt;/P&gt;</description>
    <pubDate>Sun, 03 Feb 2019 14:32:37 GMT</pubDate>
    <dc:creator>milidna13</dc:creator>
    <dc:date>2019-02-03T14:32:37Z</dc:date>
    <item>
      <title>using map and if/isnull but missing fields in base is causing failure</title>
      <link>https://community.splunk.com/t5/Splunk-Search/using-map-and-if-isnull-but-missing-fields-in-base-is-causing/m-p/443528#M125822</link>
      <description>&lt;P&gt;hi could someone please help me out here. been stuck with a problem. we have multiple existing queries in our environment. i am creating a sort of universal macro to work with the current queries.&lt;/P&gt;

&lt;P&gt;the problem is, there are some fields which exists in some of the base queries but doesnt exist in another. how do i do a map in that macro with and if/isnull even with the missing fields.&lt;/P&gt;

&lt;P&gt;Example&lt;/P&gt;

&lt;P&gt;base search1 below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval field1="abc"
| eval field2="def"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;base search2 below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval field1="abc"
| eval field2="def"
| eval field3="opq"
| eval field4="rst"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;macro below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| map [search index=test1...
| eval field1=if(isnull("$field1$"),"","$field1$")
| eval field2=if(isnull("$field2$"),"","$field2$")
| eval field3=if(isnull("$field3$"),"","$field3$")
| eval field4=if(isnull("$field4$"),"","$field4$")]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;so the thing is, map will fail for base search1 but working on base search2. is there a way to fix this? there multiple fields in the base query.&lt;/P&gt;

&lt;P&gt;thanks!&lt;/P&gt;</description>
      <pubDate>Sun, 03 Feb 2019 14:32:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/using-map-and-if-isnull-but-missing-fields-in-base-is-causing/m-p/443528#M125822</guid>
      <dc:creator>milidna13</dc:creator>
      <dc:date>2019-02-03T14:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: using map and if/isnull but missing fields in base is causing failure</title>
      <link>https://community.splunk.com/t5/Splunk-Search/using-map-and-if-isnull-but-missing-fields-in-base-is-causing/m-p/443529#M125823</link>
      <description>&lt;P&gt;Can you add a check for blank value as well, try this: | eval field1=if(isnull($field1$) OR field1 = "","",$field1$)&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 05:30:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/using-map-and-if-isnull-but-missing-fields-in-base-is-causing/m-p/443529#M125823</guid>
      <dc:creator>jvishwak</dc:creator>
      <dc:date>2019-02-04T05:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: using map and if/isnull but missing fields in base is causing failure</title>
      <link>https://community.splunk.com/t5/Splunk-Search/using-map-and-if-isnull-but-missing-fields-in-base-is-causing/m-p/443530#M125824</link>
      <description>&lt;P&gt;@milidna13 &lt;/P&gt;

&lt;P&gt;You need to place a test of fields before map command always. If you are creating a macro then try to do it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  eval field1 = if(isnull(field1),"", field1) | eval field2 = if(isnull(field2),"", field2) | eval field3 = if(isnull(field3),"", field3) | eval field4 = if(isnull(field4),"", field4)
     | map [| eval field1=if(isnull("$field1$"),"","$field1$")
     | eval field2=if(isnull("$field2$"),"","$field2$")
     | eval field3=if(isnull("$field3$"),"","$field3$")
     | eval field4=if(isnull("$field4$"),"","$field4$")  ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Feb 2019 08:22:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/using-map-and-if-isnull-but-missing-fields-in-base-is-causing/m-p/443530#M125824</guid>
      <dc:creator>vishaltaneja070</dc:creator>
      <dc:date>2019-02-04T08:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: using map and if/isnull but missing fields in base is causing failure</title>
      <link>https://community.splunk.com/t5/Splunk-Search/using-map-and-if-isnull-but-missing-fields-in-base-is-causing/m-p/443531#M125825</link>
      <description>&lt;P&gt;Yes, in the base search, end it with this command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | fields field1 field2 field3 field4 AND ALSO ANY OTHER FIELDS THAT YOU NEED TO KEEP ALL LISTED OUT HERE
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Feb 2019 17:24:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/using-map-and-if-isnull-but-missing-fields-in-base-is-causing/m-p/443531#M125825</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-02-04T17:24:31Z</dc:date>
    </item>
  </channel>
</rss>

