# Ruby filter in logstash

**URL:** <https://discuss.elastic.co/t/ruby-filter-in-logstash/305952>\
**Category:** Logstash\
**Created:** [May 30, 2022, 12:36pm UTC](https://discuss.elastic.co/t/ruby-filter-in-logstash/305952 "2022-05-30T12:36:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iss](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@Iss](https://discuss.elastic.co/u/Iss)\
**Post date:** [May 30, 2022, 12:36pm UTC](https://discuss.elastic.co/t/ruby-filter-in-logstash/305952/1 "2022-05-30T12:36:26Z")

</div>

Hi!

I have a list of geo\_points `coverage: [{"lon": ***, "lat":*** } , {"lon": ***, "lat":*** },...] `in a field (coverage) but logstash reads them as text.

I put a new location (type geo\_point) tremplate

```auto
	PUT logstash_h5
{
  "mappings": {
      "properties": {
        "location": {
          "type": "geo_point"
        }
      }
    }
}

```

and I would like to to convert all the geo\_points of the text field to geo\_points in the new location field.

I tried to do that with the following filter code but it doesn't work:

```auto
ruby{
	code => "
		event.get('[metas][dc:coverage]').each do |item|
			if item['lat']!=''
				event.set(item['lon'], '[location][lon]')
			end
			if item['lon']!=''
				event.set(item['lat'], '[location][lat]')
			end
		end
		"
    }

```

What is wrong please?  
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:** [May 30, 2022, 4:18pm UTC](https://discuss.elastic.co/t/ruby-filter-in-logstash/305952/2 "2022-05-30T16:18:31Z")

</div>

> [@Iss](#):
>
> `event.set(item['lon'], '[location][lon]')`

That appears to be the wrong way around . It probably sets item[lon] to nil, since that will not exist yet.

---

<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:** [June 27, 2022, 4:19pm UTC](https://discuss.elastic.co/t/ruby-filter-in-logstash/305952/3 "2022-06-27T16:19:09Z")

</div>

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