简体   繁体   English

我如何注册一个自定义转换器,以便@GeoShapeField 可以使用它?

[英]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.

相关问题 如何在 NestedField 中通过 Django GeoShapeField 将多边形数据保存在 Elasticsearch 上? - How to save polygon data on Elasticsearch through Django GeoShapeField inside NestedField? Elasticsearch-索引未获取任何文档 - Elasticsearch - Reindex Picks Up No Documents 如何在EC2上设置ElasticSearch节点,使其具有一致的DNS条目? - How do I set up ElasticSearch nodes on EC2 so they have consistent DNS entries? 如何使用 Spring 数据 Elasticsearch 实现字段的自定义转换器? - How to implement the custom converter for a field using Spring Data Elasticsearch? Java stacktrace 的多行解析仅提取几行 | Elasticsearch - Multiline parsing of Java stacktrace picks up few lines only | Elasticsearch "如何配置 elasticsearch 以将文档保留长达 30 天?" - How do I configure elasticsearch to retain documents up to 30 days? elasticsearch:我如何分组字段和平均总数? - elasticsearch: how do I groupby a field and avg up totals? ElasticSearch,Logstash,MySQL:如何加快大导入速度? - ElasticSearch, Logstash, MySQL: how do I speed up a large import? 我如何 map 由 fscrawler 创建的索引,以便我可以对文档进行精确的全文搜索? - How do I map an index created by fscrawler so that I can do exact full text search on the document? 在 ElasticSearch 中,如何查看自定义分析器发出的令牌? - In ElasticSearch how do I see tokens emitted by a custom analyzer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM