当尝试从我的索引中的记录动态搜索纬度时,我获得了非法的纬度值。在查看我的索引时,我看不到任何无效的纬度和经度值,所以我猜测它是我的代码中的错误。
确切错误;
{"type":"query_parsing_exception","reason":"illegal latitude value [269.99999983236194] for [geo_distance]","index":"addresses","line":1,"col":172}}]},"status":400}
搜索的型号代码;
def self.search(query)
__elasticsearch__.search(
{
query:{
multi_match: {
query: query,
fields: ['full_address']
}
},
filter:{
geo_distance:{
distance: "6miles",
location: "address.location"
}
}
}
)
end
映射;
{ "addresses" : {
"mappings" : {
"address" : {
"properties" : {
"county" : {
"type" : "string"
},
"full_address" : {
"type" : "string"
},
"location" : {
"type" : "geo_point"
}
}
}
}
} }
答案 0 :(得分:3)
我今天遇到了同样的错误,但经历过。原来Elasticsearch版本2.0和更新版仅允许-180..180范围内的经度值。
例如版本1.7.5(我在我的本地环境中)使用范围-180..180和0..360。
您的错误说明:
非法纬度值[269.99999983236194]
对于纬度,只允许范围为-90..90的值。
唯一的解决方法是在将lat / long值发送到Elasticsearch之前重新计算它们。例如,经度你可以这样做:
((longitude.to_f + 180) % 360) - 180
答案 1 :(得分:0)
用这样的东西来清理经度会更好:
$adjustedLongitude = function($vongitude) {
$result = $vongitude - 360 * floor($vongitude / 360);
if (abs($result) > 180) {
$result = 360 - $result;
}
return $result;
}