# GeoPoint in Java not mapping geo\_point

**URL:** <https://discuss.elastic.co/t/geopoint-in-java-not-mapping-geo-point/251682>\
**Category:** Elasticsearch\
**Created:** [October 11, 2020, 1:32pm UTC](https://discuss.elastic.co/t/geopoint-in-java-not-mapping-geo-point/251682 "2020-10-11T13:32:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aatif26](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@aatif26](https://discuss.elastic.co/u/aatif26)\
**Post date:** [October 11, 2020, 1:32pm UTC](https://discuss.elastic.co/t/geopoint-in-java-not-mapping-geo-point/251682/1 "2020-10-11T13:32:58Z")

</div>

I am using ElasticSearch and JAVA REST High Level Client v7.9  
Following is my agent class

```
public class Agent {

    private GeoPoint location;
    private long timestamp;
    private long available;

    public Agent(GeoPoint location, long timestamp) {
        this.location = location;
        this.timestamp = timestamp;
        available = 0;
    }
}

```

As you can see Im using a GeoPoint field. I want to map this as `geo_point` field of elasticserch.  
When I check the mapping in postman I see the following output

```
GET localhost:9200/agents/_mapping

    "agents": {
        "mappings": {
            "properties": {
                "available": {
                    "type": "long"
                },
                "location": {
                    "properties": {
                        "lat": {
                            "type": "float"
                        },
                        "lon": {
                            "type": "float"
                        }
                    }
                },
                "timestamp": {
                    "type": "long"
                }
            }
        }
    }

```

However when I first create a mapping for my index

```
PUT localhost:9200/agents/_mapping   

"properties" : {
    "location" : { "type" : "geo_point"},
    "timestamp" : { "type" : "long"},
    "available" : { "type" : "long"}
}

```

I get the expected output as below

```
"agents": {
    "mappings": {
        "properties": {
            "available": {
                "type": "long"
            },
            "location": {
                "type": "geo_point"
            },
            "timestamp": {
                "type": "long"
            }
        }
    }
}

```

As mappings are now deprecated, I want to understand what is the issue here. I am adding java objects to elasticsearch by converting them to json strings. The mapping is automatically created for other datatypes but it is unable to read geo\_point fields.

---

<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:** [October 11, 2020, 1:53pm UTC](https://discuss.elastic.co/t/geopoint-in-java-not-mapping-geo-point/251682/2 "2020-10-11T13:53:33Z")

</div>

Mappings are not deprecated at all. You need to define the mapping as you did.

---

<div class="post-metadata">

**Author:** ![aatif26](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@aatif26](https://discuss.elastic.co/u/aatif26)\
**Post date:** [October 11, 2020, 2:07pm UTC](https://discuss.elastic.co/t/geopoint-in-java-not-mapping-geo-point/251682/3 "2020-10-11T14:07:22Z")

</div>

@dadoonet I read somewhere that elasticsearch can automatically figure out the mapping for you. While it works fine for primitive types, it doesn't work for `geo_point`

So I was wondering can we achieve this without creating a mapping.

And If I create a mapping, I can declare the location field as either String or GeoPoint, it works both ways, which is also weird for me.

And I read [this](https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html)

---

<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:** [October 11, 2020, 5:15pm UTC](https://discuss.elastic.co/t/geopoint-in-java-not-mapping-geo-point/251682/4 "2020-10-11T17:15:04Z")

</div>

> [@aatif26](#):
>
> I read somewhere that elasticsearch can automatically figure out the mapping for you.

Yes but not for geopoints as you figured it out.

> [@aatif26](#):
>
> So I was wondering can we achieve this without creating a mapping.

No

> [@aatif26](#):
>
> And If I create a mapping, I can declare the location field as either String or GeoPoint, it works both ways, which is also weird for me.

I don't think it is. Would be happy to read a full reproduction script that shows it though.

> [@aatif26](#):
>
> And I read [this](https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html)

Types are gone. Not mapping.

---

<div class="post-metadata">

**Author:** ![ronny\_pachano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ronny_pachano/32/76995_2.png) [@ronny\_pachano](https://discuss.elastic.co/u/ronny_pachano)\
**Post date:** [October 11, 2020, 7:25pm UTC](https://discuss.elastic.co/t/geopoint-in-java-not-mapping-geo-point/251682/5 "2020-10-11T19:25:46Z")

</div>

Hola, encontraste la solución al problema? tengo el mismo problema, te agradecería que si encontraste la solución me la puedes compartir.

---

<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:** [October 12, 2020, 5:58am UTC](https://discuss.elastic.co/t/geopoint-in-java-not-mapping-geo-point/251682/6 "2020-10-12T05:58:04Z")

</div>

> [@ronny\_pachano](#):
>
> Hola, encontraste la solución al problema? tengo el mismo problema, te agradecería que si encontraste la solución me la puedes compartir.

Please translate your text to english as this part of the forum is in english and some people (including myself) won't be able to read it and help.

Thanks !

---

<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:** [November 9, 2020, 5:58am UTC](https://discuss.elastic.co/t/geopoint-in-java-not-mapping-geo-point/251682/7 "2020-11-09T05:58:13Z")

</div>

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