英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论