我正在使用 spring-boot 1.5.1 和 Elasticsearch 2.3.5(用于 Mahout 推荐系统),所以我在映射方面遇到问题:
@GeoPointField
private GeoPoint location;
来自包:
org.springframework.data.elasticsearch.core.geo;
所以,通过 localhost:9200/.../.../_mapping?pretty=1我有:
location: {
properties: {
lat: {
type: "double"
},
lon: {
type: "double"
}
}
}
但是,我想要位置字段的 geo_point 类型。
结果,当我尝试时:
CriteriaQuery query = new CriteriaQuery(new Criteria("location").within(startLocation, range));
我有:
QueryParsingException[failed to find geo_point field [location]]
有人知道解决办法吗? 谢谢
最佳答案
问题出在你的映射上。它应该是 geo_point 类型。例如
您可以使用curl PUT来做到这一点
curl -XPUT 'http://localhost:9200/your_index/_mapping/your_type' -d '
{
"your_type" : {
"properties" : {
"phone": {
"type": "string", "index": "not_analyzed"
},
"webSite": {
"type": "string", "index": "not_analyzed"
}
"location": {
{"type": "geo_point"}
}
}
}
'
保存数据时,您可以执行以下操作:
"location":{
"lat":11.68036,
"lon":-93.3103
}
关于java - @GeoPointField Elasticsearch 的错误映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42417417/