# Convert latitude and longitude fields into geo\_point type,

**URL:** <https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364>\
**Category:** Elasticsearch\
**Created:** [January 24, 2020, 5:40am UTC](https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364 "2020-01-24T05:40:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bondelastic](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@bondelastic](https://discuss.elastic.co/u/bondelastic)\
**Post date:** [January 24, 2020, 5:40am UTC](https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364/1 "2020-01-24T05:40:41Z")

</div>

Hello,  
I have the below fields in my index.

index pattern : s3-\*  
service.action.networkConnectionAction.remoteIpDetails.geoLocation.lat - type is number  
service.action.networkConnectionAction.remoteIpDetails.geoLocation.lon - type is number

service.action.portProbeAction.portProbeDetails.remoteIpDetails.geoLocation.lat - type is number  
service.action.portProbeAction.portProbeDetails.remoteIpDetails.geoLocation.lon - type is number  
I am trying to plot a coordinated map using the above fields. However Kibana requires the fields to be of geo\_point type. I tried using a template as below ( ES 7.1 )

PUT \_template/gdt  
{  
"template": "s3-\*",  
"settings": {},  
"mappings": {  
"properties": {  
"service.action.portProbeAction.portProbeDetails.remoteIpDetails.geoLocation": {  
"type": "geo\_point"  
},  
"service.action.networkConnectionAction.remoteIpDetails.geoLocation": {  
"type": "geo\_point"  
}  
}  
}  
}

However no luck in getting it to work. Any advise?

---

<div class="post-metadata">

**Author:** ![bondelastic](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@bondelastic](https://discuss.elastic.co/u/bondelastic)\
**Post date:** [January 26, 2020, 4:39am UTC](https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364/2 "2020-01-26T04:39:58Z")

</div>

Anyone any inputs please?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 26, 2020, 7:57am UTC](https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364/3 "2020-01-26T07:57:19Z")

</div>

Welcome!

Could you please check what the actual mapping is for your index?

---

<div class="post-metadata">

**Author:** ![bondelastic](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@bondelastic](https://discuss.elastic.co/u/bondelastic)\
**Post date:** [January 26, 2020, 7:59am UTC](https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364/4 "2020-01-26T07:59:55Z")

</div>

Hello, The current mapping is as below  
"geoLocation" : {  
"properties" : {  
"lat" : {  
"type" : "float"  
},  
"lon" : {  
"type" : "float"  
}  
}  
},

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 26, 2020, 9:09am UTC](https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364/5 "2020-01-26T09:09:32Z")

</div>

So it's seems that your index has not been created using the template.

---

<div class="post-metadata">

**Author:** ![bondelastic](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@bondelastic](https://discuss.elastic.co/u/bondelastic)\
**Post date:** [January 26, 2020, 6:23pm UTC](https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364/6 "2020-01-26T18:23:04Z")

</div>

Basically, I am using requests.post to create and load the json file to ES. If I execute the template API provided in my question, it creates the mapping as per the template. However, when the process is ran, it can't load the data into ES and fails with a 400 error. It seems to be failing because the json data contains many other fields and not just the "lon" and "lat" fields. Basically, I was using the fields as per the content of the json data in ES.

This is the python code snippet  
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}  
resp = requests.post(es\_Url, auth=awsauth, headers=headers, json=docData)

In the above, the docData is basically the son load of the file content  
docData = json.loads(line)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 26, 2020, 6:54pm UTC](https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364/7 "2020-01-26T18:54:50Z")

</div>

I don't have a clear understanding of what you are doing and how.

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![bondelastic](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@bondelastic](https://discuss.elastic.co/u/bondelastic)\
**Post date:** [January 26, 2020, 7:36pm UTC](https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364/8 "2020-01-26T19:36:20Z")

</div>

Apologies for the confusion. Summarizing my problem as below

1. I am using a python script to create index and load the son data into ES. Specifically using the python module "requests.post".
2. The index is created just fine. The fields and mappings are created just fine as per the contents of the son data.
3. The mapping is created as below. Notice the fields "Lon" and "lat" are of the float type in the mapping for geoLocation.
4. I wanted to create a visualisation using coordinated map using the above fields mentioned. However ES expects the type to be geo\_point. Now, my question is - how do I convert it to a geo\_point type?  
"service" : {  
"properties" : {  
"action" : {  
"properties" : {  
"actionType" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"dnsRequestAction" : {  
"properties" : {  
"blocked" : {  
"type" : "boolean"  
},  
"domain" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"protocol" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
}  
}  
},  
"networkConnectionAction" : {  
"properties" : {  
"blocked" : {  
"type" : "boolean"  
},  
"connectionDirection" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"localPortDetails" : {  
"properties" : {  
"port" : {  
"type" : "long"  
},  
"portName" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
}  
}  
},  
"protocol" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
},  
"remoteIpDetails" : {  
"properties" : {  
"city" : {  
"properties" : {  
"cityName" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
}  
}  
},  
"country" : {  
"properties" : {  
"countryName" : {  
"type" : "text",  
"fields" : {  
"keyword" : {  
"type" : "keyword",  
"ignore\_above" : 256  
}  
}  
}  
}  
},  
"geoLocation" : {  
"properties" : {  
"lat" : {  
"type" : "float"  
},  
"lon" : {  
"type" : "float"  
}  
}  
},

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 27, 2020, 1:29am UTC](https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364/9 "2020-01-27T01:29:36Z")

</div>

You need to create the proper mapping when you create your index then index the data.  
You can't change it after.  
Here you need to reindex your data.

---

<div class="post-metadata">

**Author:** ![bondelastic](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@bondelastic](https://discuss.elastic.co/u/bondelastic)\
**Post date:** [January 29, 2020, 10:51pm UTC](https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364/10 "2020-01-29T22:51:56Z")

</div>

Thanks. I believe the issue is with the python module. If I create the mappings beforehand and then try to write the data, it just fails to do so.

---

<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 26, 2020, 10:52pm UTC](https://discuss.elastic.co/t/convert-latitude-and-longitude-fields-into-geo-point-type/216364/11 "2020-02-26T22:52:01Z")

</div>

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