# Latitude and Longitude Error in logstash?

**URL:** https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855
**Category:** Logstash
**Created:** [January 10, 2022, 7:34am UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855 "2022-01-10T07:34:16Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![padamrai](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@padamrai](https://discuss.elastic.co/u/padamrai)
#### Post date: [January 10, 2022, 7:34am UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/1 "2022-01-10T07:34:16Z")

</div>

Hello Everyone,

I am trying to convert PostalCode to lat and long, I have done this task but Now I am confuse how to convert it into **geopoint field**

I have tried in logstash but no success so for, getting error.  
My config file:

```auto
mutate {
        add_field => ["[location]", "%{lat}"]
        add_field => ["[location]", "%{lon}"]
}
mutate{
        convert => ["[location]", "float"]
    }

```

Output Looks Like:

```auto
 "location" => [
        [0] 61.9814,
        [1] -132.4242
    ],

```

Error I am getting in logstash:

```auto
 Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, 
:_index=>"caary_time_test", :routing=>nil, :_type=>"_doc"}, #
<LogStash::Event:0x1537f1d7>], :response=>{"index"=>{"_index"=>"caary_time_test", 
"_type"=>"_doc", "_id"=>"O8sRQ34BZIkRPQRnvuZL", "status"=>400, "error"=>
{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse field [lon] of type 
[geo_point]", "caused_by"=>{"type"=>"parse_exception", "reason"=>"unsupported 
symbol [-] in geohash [-132.4242]", "caused_by"=>{"type"=>"illegal_argument_exception",
 "reason"=>"unsupported symbol [-] in geohash [-132.4242]"}}}}}}

```

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 10, 2022, 12:38pm UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/2 "2022-01-10T12:38:10Z")

</div>

Try reversing your `add_field` order.

If you look at the [examples](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html) Lat always becomes before Long except when you have it as an array. I don't know why.

```auto
mutate {
        add_field => ["[location]", "%{lon}"]
        add_field => ["[location]", "%{lat}"]
}

```

---

<div class="post-metadata">

### Author: ![padamrai](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@padamrai](https://discuss.elastic.co/u/padamrai)
#### Post date: [January 10, 2022, 12:39pm UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/3 "2022-01-10T12:39:03Z")

</div>

I have tried that way also but getting no success.

---

<div class="post-metadata">

### Author: ![padamrai](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@padamrai](https://discuss.elastic.co/u/padamrai)
#### Post date: [January 10, 2022, 12:39pm UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/4 "2022-01-10T12:39:43Z")

</div>

I think it is not meeting the requirement of geopoint datatypes.

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 10, 2022, 12:41pm UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/5 "2022-01-10T12:41:06Z")

</div>

What does your mapping look like? This works if you run it in Dev Tools.

```auto
PUT test-geo
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_point"
      }
    }
  }
}

PUT test-geo/_doc
{
  "location": [-132.4242, 61.9814]
}

```

---

<div class="post-metadata">

### Author: ![padamrai](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@padamrai](https://discuss.elastic.co/u/padamrai)
#### Post date: [January 10, 2022, 12:44pm UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/6 "2022-01-10T12:44:52Z")

</div>

It works fine, Actually I am getting postalCodes in incoming file then converting that postalCodes to latitude and longitude. Now I am facing problem how to convert lat and lon to geopoints.

---

<div class="post-metadata">

### Author: ![padamrai](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@padamrai](https://discuss.elastic.co/u/padamrai)
#### Post date: [January 10, 2022, 12:45pm UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/7 "2022-01-10T12:45:46Z")

</div>

> [@aaron-nimocks](#):
>
> `[-132.4242, 61.9814]`

How I can get such type of format in logstash to map geopoints.

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 10, 2022, 12:57pm UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/8 "2022-01-10T12:57:56Z")

</div>

Should be from what I posted above.

```auto
mutate {
        add_field => ["[location]", "%{lon}"]
        add_field => ["[location]", "%{lat}"]
}

```

---

<div class="post-metadata">

### Author: ![padamrai](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@padamrai](https://discuss.elastic.co/u/padamrai)
#### Post date: [January 10, 2022, 1:11pm UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/9 "2022-01-10T13:11:13Z")

</div>

lon and lat are in float or string?

---

<div class="post-metadata">

### Author: ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)
#### Post date: [January 10, 2022, 1:16pm UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/10 "2022-01-10T13:16:51Z")

</div>

There are a handful ways to format a `geo_point`. I usually just choose this method so you don't need to mess with arrays or data types.

**Conf**

```auto
input {
  generator {
    message => '[{ "lat": "61.9814", "lon":"-132.4242" }]'
    count => 1
    codec => "json"
  }
}
filter {
  mutate {
   add_field => ["[location]", "%{lat},%{lon}"]
  }
}
output {
  stdout { codec => "json" }
}

```

**Output**

```auto
"location": "61.9814,-132.4242"

```

---

<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: [January 10, 2022, 2:59pm UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/11 "2022-01-10T14:59:57Z")

</div>

> [@padamrai](#):
>
> lon and lat are in float or string?

It does not matter. To get a geo\_point in elasticsearch you _must_ have a mapping that says the field is a geo\_point. Once you have that elasticsearch will parse anything like

"location": "41.12,-71.34"  
"location": "drm3btev3e86"  
"location": [-71.34, 41.12] ,  
"location" : "POINT (-71.34 41.12)"

and probably some others.

---

<div class="post-metadata">

### Author: ![padamrai](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@padamrai](https://discuss.elastic.co/u/padamrai)
#### Post date: [January 11, 2022, 4:35am UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/12 "2022-01-11T04:35:23Z")

</div>

@aaron-nimocks Thanks Dear for your cooperation.

---

<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: [February 8, 2022, 4:35am UTC](https://discuss.elastic.co/t/latitude-and-longitude-error-in-logstash/293855/13 "2022-02-08T04:35:41Z")

</div>

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