[英]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.我正在使用 spring-data-elasticsearch (5) 自动将第三方数据写入 ES (8) 索引。 The data contains geodata in GML format, which is parsed into a nested
Map<String, Object>
.数据包含 GML 格式的地理数据,它被解析为嵌套的
Map<String, Object>
。
In my POJO I have a field在我的 POJO 中,我有一个字段
@GeoShapeField
private Map<String, Object> geometry;
This is written perfectly fine in many cases;在许多情况下,这写得非常好; however, the data I get can also contain eg
Envelope
, which is not supported by GeoJson but could be imported without problems into ES.然而,我得到的数据也可以包含例如
Envelope
,它不受 GeoJson 支持,但可以毫无问题地导入到 ES 中。
I can write simple custom ReadingConverter
/ WritingConverter
s - but how can I register them in a way that @GeoShapeField
automatically chooses them when appropriate?我可以编写简单的自定义
ReadingConverter
/ WritingConverter
s - 但是如何以@GeoShapeField
在适当时自动选择它们的方式注册它们?
I see that org.springframework.data.elasticsearch.core.convert.GeoConverters
is responsible for choosing the correct converter, esp.我看到
org.springframework.data.elasticsearch.core.convert.GeoConverters
负责选择正确的转换器,尤其是。 .GeoJsonToMapConverter
and .MapToGeoJsonConverter
. .GeoJsonToMapConverter
和.MapToGeoJsonConverter
。 How would I correctly extend the class/replace it, so that @GeoShapeField looks for an additional (or more) type(s)?我将如何正确地扩展类/替换它,以便 @GeoShapeField 查找其他(或更多)类型?
As pointed out by PJMeisch in the comments, I had several understanding problems, which led to the formulation of the question.正如 PJMeisch 在评论中指出的那样,我有几个理解问题,导致问题的制定。
The answer to my actual question is straightforward: for Envelope, Elasticsearch expects我的实际问题的答案很简单:对于 Envelope,Elasticsearch 期望
"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>
:要使用 spring-data-elasticsearch 实现这一点,提供一个简单的转换为
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.
但是,ES 需要边界框的左上角和右下角。 After switching the respective positions, everything works now.
交换各自的位置后,现在一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.