GeoPoint in Java not mapping geo_point

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.

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

@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

Yes but not for geopoints as you figured it out.

No

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

Types are gone. Not mapping.

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 !

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