Spring 数据 Elasticsearch 中的自定义 GeoPoint 对象

Custom GeoPoint object in Spring Data Elasticsearch

使用 spring 启动 2.3.4.

有没有办法使用自定义 GeoPoint 对象而不是 org.springframework.data.elasticsearch.core.geo.GeoPoint?

如果是这样,如何覆盖映射? putMapping 已弃用。

@Document(indexName="myIndex")
public class MyDocument{
    @GeoPointField
    private MyPositionDocument position;
    // currently this only works with
    // private GeoPoint position;

您已经有了第一部分,用 @GeoPointField 注释 属性。这确保将写入正确的索引映射,以便 position 的类型将为 geo_point.

接下来,您需要创建自定义转换器以将 MyPositionDocument 转换为 Elasticsearch (https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html#geo-point) 支持的类型,并为另一个方向创建一个转换器。

关于注册自定义转换器,请参阅https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.mapping.meta-model.conversions