Spring Elicsearch Geo Data Type for Multipoint Use

We are currently using spring data lookup. I would like to create a field of type geo_shape to create a multipoint field with multiple geoJson coordinate points. I see that the project supports GeoPointFields, but does not see Geo Shapes.

Is there any way to specify geo_shape?

If not, I see that there is a custom mapping object. Can we just point out the Geo Shape in the template / mappings and use some kind of custom object to map what we need.

+4
source share
2 answers

I don’t know if this helps, but what I did was build a class

import com.fasterxml.jackson.databind.JsonNode;
public static class GeoShape {
        String type;
        JsonNode coordinates;
        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public JsonNode getCoordinates() {
            return coordinates;
        }

        public void setCoordinates(JsonNode coordinates) {
            this.coordinates = coordinates;
        }
    }

- elasticsearch, spring /.

0

@m1416 - ES.

, JPA/Hibernate ES, . Hibernate , . json-, , .

, , , ES, .

JsonNodeConverter:

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.persistence.AttributeConverter;
import java.io.IOException;

public class JsonNodeConverter implements AttributeConverter<JsonNode, String> {

    @Override
    public String convertToDatabaseColumn(JsonNode jsonNode){
        if (jsonNode == null  || jsonNode.asText() == null) {
            return null;
        }
        return jsonNode.asText();

    }

    @Override
    public JsonNode convertToEntityAttribute(String s) {
        if (s == null || s.length() == 0) {
            return null;
        }
        ObjectMapper mapper = new ObjectMapper();
        JsonNode jsonNode = null;
        try {
            jsonNode = mapper.readTree(s);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return jsonNode;
    }
}

, JsonNode :

@Column(name="geography", columnDefinition="LONGTEXT")
@Convert(converter=JsonNodeConverter.class)
private JsonNode geometry;
0

All Articles