【发布时间】:2019-08-27 13:49:06
【问题描述】:
我正在开发一个微服务,用于使用 spring-data-elasticsearch 使用 Java/Spring Boot 管理位置,当尝试使用我的控制器向 ES 输入新数据时,数据输入未正确映射到 ES 中的文档,特别是地理点属性“位置”。
我尝试使用来自 import org.springframework.data.elasticsearch.core.geo.GeoPoint 和来自 org.springframework.data.elasticsearch.core.geo.GeoPoint 的 GeoPoint,在这两种情况下都没有输入保存到 ES 的数据作为geo_point
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.GeoPointField;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import io.swagger.annotations.ApiModelProperty;
@Document(indexName = "location", type="location")
public class Location {
@Id
@ApiModelProperty(hidden = true)
private String id;
private String appId;
private String resourceId;
@GeoPointField
private GeoPoint location;
private String street;
private String city;
// more attr and method was ommited
}
使用 ElasticSearchRepository 将数据保存到 ES 后,当我获取映射数据时显示如下:
{
"location" : {
"mappings" : {
"location" : {
"properties" : {
"appId" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"city" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"country" : {
"properties" : {
"countryCcFips" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"countryCcIso" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"countryName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"location" : {
"properties" : {
"lat" : {
"type" : "float"
},
"lon" : {
"type" : "float"
}
}
},
"parish" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
// ommited more json data
请,我需要将 GeoPoint 字段(位置)映射到 ES 中的 geo_point,这对于正确执行 Geoqueries 很重要。
我使用 Spring Data ElasticSearch,使用 Spring Boot 2.1.3.RELEASE 和 ElasticSearch driver 6.4.3,使用 ElasticSearch server 6.4
【问题讨论】:
-
这确实很奇怪,我刚刚检查了代码,通常您只需要拥有
GeoPoint类或GeoPointField注释即可将字段键入为“geo_point”。代码中的这个位置多年来一直没有改变。我将尝试用本地示例重现这一点,但不能保证我今天会找到时间。
标签: java elasticsearch geo spring-data-elasticsearch