# Failing to index geo\_shape data into Elasticsearch from Logstash (nil values)

**URL:** <https://discuss.elastic.co/t/failing-to-index-geo-shape-data-into-elasticsearch-from-logstash-nil-values/303193>\
**Category:** Logstash\
**Created:** [April 25, 2022, 6:32pm UTC](https://discuss.elastic.co/t/failing-to-index-geo-shape-data-into-elasticsearch-from-logstash-nil-values/303193 "2022-04-25T18:32:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scottfred](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/scottfred/32/102384_2.png) [@scottfred](https://discuss.elastic.co/u/scottfred)\
**Post date:** [April 25, 2022, 6:32pm UTC](https://discuss.elastic.co/t/failing-to-index-geo-shape-data-into-elasticsearch-from-logstash-nil-values/303193/1 "2022-04-25T18:32:09Z")

</div>

I have Ruby code in Logstash that parses a CSV file and reads the data. Some fields of the data can be empty (e.g. ,,,). When the data is empty, Ruby's CSV parse converts the data to an empty string, (e.g. ""). I also have an Index that defines these fields as a "geo\_shape". So, when Elasticsearch receives the empty string, "", it fails to parse it with the error:

```auto
"error" => "type" => "mapper_parsing_exception" => "failed to parse field [parametrics.location (L)] of type [geo_shape], "caused by" => "type" => "parse_exception", "expected word but found: END-OF-STREAM"}}}}

```

I was able to verify using Kibana \> DevTools that I could create the index and then POST data to it IF the value was changed from an empty string, "" to NULL.

BUT, I can't figure out how to tell Logstash to set the NULL value from within the Ruby Code section. Here's what I've tried.

Index:

```auto
PUT data
{
  "mappings": {
     "properties": {
         "parametrics": {
             "properties": {
                  "location (L)": {
                      "type": "geo_shape"
                  }
              }
         }
      }
   }
}

```

Snippet of the Logstash Ruby Filter (NOTE: the actual Ruby code prior to this snippet correctly parses the CSV file because when the value is NOT empty, it correctly populates the data fields, the problem I am trying to resolve only exists when the value is "nil", empty, not populated in the CSV):

```auto
...
ruby {
   code => '
      event.get("parametrics", parametrics)
      
      if parametrics["location (L)]" == ""
           event.set("parametrics[location (L)", nil)
     end
  '
   }
...

```

Ruby debug output:

```auto
"parametrics" => {
    "location (L)" => ""
}

```

Ultimately, what I'm trying to do is figure out how to populate the resulting JSON document that gets sent to Elasticsearch to have NULL in the field that is empty. So, when the value that is being parsed is something like, "LINESTRING(lon1 lat1, lon2 lat2, lon3 lat3)", the data is correctly parsed into Elasticsearch as geo\_shape (WKT) format.

Thanks

---

<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 25, 2022, 9:55pm UTC](https://discuss.elastic.co/t/failing-to-index-geo-shape-data-into-elasticsearch-from-logstash-nil-values/303193/2 "2022-04-25T21:55:17Z")

</div>

I would expect you to be getting \_rubyexception with that. The `event.get("parametrics", parametrics)` should be `parametrics = event.get("parametrics")` and

```
event.set("parametrics[location (L)", nil)

```

should be

```
event.set("[parametrics][location (L)]", nil)
```

---

<div class="post-metadata">

**Author:** ![scottfred](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/scottfred/32/102384_2.png) [@scottfred](https://discuss.elastic.co/u/scottfred)\
**Post date:** [April 26, 2022, 9:22pm UTC](https://discuss.elastic.co/t/failing-to-index-geo-shape-data-into-elasticsearch-from-logstash-nil-values/303193/3 "2022-04-26T21:22:50Z")

</div>

Thanks @Badger, I had to type this up by hand rather than copy and paste. Your suggestions worked. As an alternative, I also just removed the key/value from a hash.

Scott

---

<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 24, 2022, 9:23pm UTC](https://discuss.elastic.co/t/failing-to-index-geo-shape-data-into-elasticsearch-from-logstash-nil-values/303193/4 "2022-05-24T21:23:31Z")

</div>

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