elasticsearchspring-datageojsonspring-data-elasticsearchgml-geographic-markup-lan

How do I register a custom converter so that @GeoShapeField picks it up?


I am using spring-data-elasticsearch (5) to automagically write third-party data into an ES (8) index. The data contains geodata in GML format, which is parsed into a nested Map<String, Object>.

In my POJO I have a field

@GeoShapeField
private Map<String, Object> geometry;

This is written perfectly fine in many cases; however, the data I get can also contain e.g. Envelope, which is not supported by GeoJson but could be imported without problems into ES.

I can write simple custom ReadingConverter/WritingConverters - but how can I register them in a way that @GeoShapeField automatically chooses them when appropriate?

I see that org.springframework.data.elasticsearch.core.convert.GeoConverters is responsible for choosing the correct converter, esp. .GeoJsonToMapConverter and .MapToGeoJsonConverter. How would I correctly extend the class/replace it, so that @GeoShapeField looks for an additional (or more) type(s)?


Solution

  • As pointed out by P.J.Meisch in the comments, I had several understanding problems, which led to the formulation of the question.

    The answer to my actual question is straightforward: for Envelope, Elasticsearch expects

    "myField": {
        "type" : "envelope",
        "coordinates" : [ [100.0, 1.0], [101.0, 0.0] ]
    }
    

    To achieve this using spring-data-elasticsearch, it is enough to provide a simple translation into a Map<String, Object>:

    Map<String, Object> myField = new HashMap<>();
    myField.put("type", "envelope");
    myField.put("coordinates", Arrays.asList(Arrays.asList(100.0, 1.0), Arrays.asList(101.0, 0.0)));
    

    The point over which I tripped was the data. I receive bounding boxes specifying lower left and upper right corners. However, ES expects upper left and lower right corners for a bounding box. After switching the respective positions, everything works now.