elasticsearch rails-非法的纬度值 [英] elasticsearch rails - illegal latitude value

查看:577
本文介绍了elasticsearch rails-非法的纬度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试从索引中的记录动态搜索纬度时,我得到了非法的纬度值.在查看索引时,我看不到任何无效的纬度和经度值,因此我猜测这是我的代码中的错误.

When trying to search from latitude dynamically from records in my index I've been getting an illegal latitude value. When looking at my index I can't see any invalid latitude and longitude values, so I'm guessing it's an error in my code.

确切错误;

{"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"
      }
    }
  }
}

} }

推荐答案

我今天遇到了相同的错误,但存在经度.证明Elasticsearch 2.0版及更高版本仅允许在-180..180范围内的经度值.

I experienced the same error today but with longitude. Turns out Elasticsearch version 2.0 and newer only allows longitude values from range -180..180.

例如版本1.7.5(我在本地环境中使用的版本)可以同时使用-180..180和0..360.

For example version 1.7.5 (which I had in my local environment) worked with both ranges -180..180 and 0..360.

您的错误状态:

非法纬度值[269.99999983236194]

illegal latitude value [269.99999983236194]

对于纬度,仅允许使用-90..90范围内的值.

For latitude, only values from range -90..90 are allowed.

唯一的解决方法是在将经度/纬度值发送到Elasticsearch之前重新计算它们.例如,对于经度,您可以执行以下操作:

The only fix is to re-compute lat/long values before sending them to Elasticsearch. For example for longitude you could do:

((longitude.to_f + 180) % 360) - 180

这篇关于elasticsearch rails-非法的纬度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆