# Error on inserting geo\_point in elasticsearch through java

**URL:** <https://discuss.elastic.co/t/error-on-inserting-geo-point-in-elasticsearch-through-java/67730>\
**Category:** Elasticsearch\
**Created:** [December 1, 2016, 8:22am UTC](https://discuss.elastic.co/t/error-on-inserting-geo-point-in-elasticsearch-through-java/67730 "2016-12-01T08:22:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankureck](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@ankureck](https://discuss.elastic.co/u/ankureck)\
**Post date:** [December 1, 2016, 8:22am UTC](https://discuss.elastic.co/t/error-on-inserting-geo-point-in-elasticsearch-through-java/67730/1 "2016-12-01T08:22:16Z")

</div>

I have an index in Elasticsearch in which there is a field of geo\_point. The mapping file is somewhat like this.  
curl -XPUT 'localhost:9200/test\_geo5' -d'  
{  
"mappings":{  
"test\_geo5":{  
"properties":{  
"lat":{ "type": "string","index": "not\_analyzed"},  
"lon":{ "type": "string","index": "not\_analyzed"},  
"message\_geocoordinates":{ "type": "geo\_point"}  
}  
}  
}  
}'

I want to insert message\_geocoordinates using java code.

So I wrote java code like this

String latitude= xxxxx;  
String longitude= yyyy;  
String message\_geocordinates= latitude+","+longitude;  
JSONObject jj = new JSONObject();  
jj.put("lat", latitude);  
jj.put("lon", longitude);  
IndexResponse response = client.prepareIndex("test\_geo5", "iiiii").setSource(jj.toString()).execute().actionGet();

and I tried to insert it in Elasticsearch. But I received following exception.  
So it says that my message\_geocoordinates field is String in java but it is GeoPointFieldType for elatic search.

How can I insert geopoint field into elasticsearch using java code.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [December 1, 2016, 12:37pm UTC](https://discuss.elastic.co/t/error-on-inserting-geo-point-in-elasticsearch-through-java/67730/2 "2016-12-01T12:37:15Z")

</div>

> There are four ways that a geo-point may be specified

From [Geo-point datatype | Elasticsearch Guide [5.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/geo-point.html)

---

<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 29, 2016, 12:37pm UTC](https://discuss.elastic.co/t/error-on-inserting-geo-point-in-elasticsearch-through-java/67730/3 "2016-12-29T12:37:30Z")

</div>

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