自定义的GeoPoint对象在Spring Data Elasticsearch中。

huangapple go评论91阅读模式
英文:

Custom GeoPoint object in Spring Data Elasticsearch

问题

使用 Spring Boot 2.3.4。

是否有一种方法可以使用自定义的 GeoPoint 对象,而不是 org.springframework.data.elasticsearch.core.geo.GeoPoint?

如果可以,如何覆盖映射?putMapping 已被弃用。

@Document(indexName="myIndex")
public class MyDocument{
    @GeoPointField
    private MyPositionDocument position;
    // 目前这只适用于
    // private GeoPoint position;
}
英文:

Using spring boot 2.3.4.

Is there a way to use a custom GeoPoint object instead of org.springframework.data.elasticsearch.core.geo.GeoPoint ?

If so, how could the mapping be overridden ? putMapping is deprecated.

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

答案1

得分: 1

你已经拥有了第一部分,使用 @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。

英文:

You already have the first part, annotating the property with @GeoPointField. This ensures that the correct index mappings will be written so that the type of position will be geo_point.

The next thing is that you will need to create custom converters to convert from a MyPositionDocument to a type that is supported by Elasticsearch (https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html#geo-point) and one converter for the other direction.

As for registering custom converters, see https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.mapping.meta-model.conversions

huangapple
  • 本文由 发表于 2020年10月27日 01:51:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/64542388.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定