# How to create map based on longitude, latitude fileds?

**URL:** <https://discuss.elastic.co/t/how-to-create-map-based-on-longitude-latitude-fileds/66664>\
**Category:** Logstash\
**Created:** [November 21, 2016, 3:07am UTC](https://discuss.elastic.co/t/how-to-create-map-based-on-longitude-latitude-fileds/66664 "2016-11-21T03:07:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![namcx](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@namcx](https://discuss.elastic.co/u/namcx)\
**Post date:** [November 21, 2016, 3:07am UTC](https://discuss.elastic.co/t/how-to-create-map-based-on-longitude-latitude-fileds/66664/1 "2016-11-21T03:07:35Z")

</div>

Hi Experts,

I had add 2 field with name lat,lon and value 21.033333, 105.849998 to index by logstash filter plugin "mutate"  
if [fields][Contract] =~ "HNH" {  
mutate {  
add\_field =\> ["city", "Hanoi"]  
add\_field =\> ["lat", 21.033333]  
add\_field =\> ["lon", 105.849998]  
}  
}  
Then, i convert lat, lon to "float"  
mutate {  
convert =\> {  
"lat" =\> "float"  
"lon" =\> "float"  
}  
add\_field =\> {  
"[geoip][location]" =\> ["%{lon}", "%{lat}"]  
"[geoip][latitude]" =\> "%{lat}"  
"[geoip][longitude]" =\> "%{lon}"  
}

}

But when start logstash, logstash show errror: "[2016-11-21T10:06:41,507][WARN][logstash.outputs.elasticsearch] Failed action. {:status=\>400, :action=\>["index", {:\_id=\>nil, :\_index=\>"logstash-test", :\_type=\>"fboxs", :\_routing=\>nil}, 2016-11-09T01:00:24.670Z 0.0.0.0 -], :response=\>{"index"=\>{"\_index"=\>"logstash-test", "\_type"=\>"fboxs", "\_id"=\>"AViE2ZLx\_lz5mWQZHGac", "status"=\>400, "error"=\>{"type"=\>"mapper\_parsing\_exception", "reason"=\>"failed to parse [geoip.latitude]", "caused\_by"=\>{"type"=\>"number\_format\_exception", "reason"=\>"For input string: "%{lat}""}}}}}"

How to fix it? Thanks.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 22, 2016, 9:13pm UTC](https://discuss.elastic.co/t/how-to-create-map-based-on-longitude-latitude-fileds/66664/2 "2016-11-22T21:13:30Z")

</div>

As the error message shows, your `[geoip][latitude]` field doesn't contain the latitude but the string "%{lat}", indicating that the `lat` field was unset when your mutate filter ran. Is that filter outside the `if [fields][Contract] =~ "HNH"` conditional? Is that really correct?

---

<div class="post-metadata">

**Author:** ![namcx](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@namcx](https://discuss.elastic.co/u/namcx)\
**Post date:** [November 23, 2016, 2:59am UTC](https://discuss.elastic.co/t/how-to-create-map-based-on-longitude-latitude-fileds/66664/3 "2016-11-23T02:59:16Z")

</div>

Tks for reply.

This json input  
{"received\_at":"2016-11-09T08:04:59+07:00","message":"-","fields":{"Contract":"HNH004399"},"@version":"1","@timestamp":"2016-11-09T01:05:00.402Z","type":"fboxs","tags":["fboxs"],"host":"0.0.0.0","year":"2016","month":"11","day":"09","hour":"08","min":"04","min\_5":0}

And if [fields][Contract] =~ "HNH" will add [city], [lon] and [lat]. So correctly?

Sorry my bad english.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 23, 2016, 6:42am UTC](https://discuss.elastic.co/t/how-to-create-map-based-on-longitude-latitude-fileds/66664/4 "2016-11-23T06:42:18Z")

</div>

> And if [fields][Contract] =~ "HNH" will add [city], [lon] and [lat]. So correctly?

Yes.

---

<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:** [December 21, 2016, 6:42am UTC](https://discuss.elastic.co/t/how-to-create-map-based-on-longitude-latitude-fileds/66664/5 "2016-12-21T06:42:40Z")

</div>

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