# Comparing to null in logstash

**URL:** <https://discuss.elastic.co/t/comparing-to-null-in-logstash/128008>\
**Category:** Logstash\
**Created:** [April 13, 2018, 3:36pm UTC](https://discuss.elastic.co/t/comparing-to-null-in-logstash/128008 "2018-04-13T15:36:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snewman](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@snewman](https://discuss.elastic.co/u/snewman)\
**Post date:** [April 13, 2018, 3:36pm UTC](https://discuss.elastic.co/t/comparing-to-null-in-logstash/128008/1 "2018-04-13T15:36:23Z")

</div>

I have a beats\>logstash\>elasticearch\>kibana pipeline to parse logfiles, some lines of which contain location data, but they all have a field for location data. Attempting to convert the empty fields to a geo\_point gives me a parse exeption and does not index that line. To fix this I am trying to only convert the fields to geo\_point if the field is populated. I am, however, having some issues with determining if the field is populated or not. I know that my code is currently comparing it to the string "null", however, if I remove the quotes or replace it with "", I get an unexpected character error. Here is my code  
input{  
beats{ port =\> 5044}  
#stdin{}  
}

filter{  
dissect{  
mapping =\> {  
"message" =\> "%{timestamp}|%{+timestamp}|%{level}|%{application}|%{module}|%{latitude}|%{longitude}|%{heading}|%{speed}|%{distance}|  
%{pulse}|%{thread}|%{cpu}|%{freq}|%{mem}|%{text}"  
}  
#convert\_datatype =\>{  
# speed =\> "float"  
#freq =\> "float"  
#}  
}  
date{  
match =\> ["timestamp", "yyyy-MM-dd'|'HH:mm:ss.SSS", "yyyy-MM-dd|HH:mm:ss.SSS", "ISO8601"]  
}

mutate{  
remove\_field =\> [message]  
}  
if [longitude] != "null" {  
mutate{  
convert =\> {"latitude" =\> "float"}  
convert =\> {"longitude" =\> "float"}

```
  rename => {
    "longitude" => "[location][lon]"
    "latitude" => "[location][lat]"
  }
}

```

}  
}

output{  
elasticsearch {  
hosts =\> ["localhost:9200"]  
index =\> "log\_index-%{+YYYY.MM.dd}"  
}

# stdout {}

}

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 13, 2018, 3:49pm UTC](https://discuss.elastic.co/t/comparing-to-null-in-logstash/128008/2 "2018-04-13T15:49:30Z")

</div>

So what is in the field? Copy and paste an event from the JSON tab in Kibana Discover.

If the field is missing or nil, then "if ![fieldname] ..." should do the job. If the field is an empty string then 'if [fieldname] != ""' should do it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 11, 2018, 3:49pm UTC](https://discuss.elastic.co/t/comparing-to-null-in-logstash/128008/3 "2018-05-11T15:49:32Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
