在弹性搜索中计算地理距离 [英] compute geo distance in elasticsearch

查看:112
本文介绍了在弹性搜索中计算地理距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 geo_distance 过滤器,我的查询中包含,并且可以正常工作:

i am using a geo_distance filter with tire in my query and it works fine:

search.filter :geo_distance, :distance => "#{request.distance}km", :location => "#{request.lat},#{request.lng}"

我预计结果将以某种方式包括计算到我用于过滤器的地理位置的距离。

i expected that the result would somehow include the computed distance to the geo-location that i used for my filter.

有没有办法告诉弹性搜索将其包含在响应中,以便我每个结果都要用红宝石计算出来?

is there a way to tell elasticsearch to include that in the response, so that i don't have to calculate it in ruby for every result?

==更新==

找到答案在Google群组中:

i found the answer in a google group:

search.sort do
  by "_geo_distance", "location" => "#{request.lat},#{request.lng}", "unit" => "km" if request.with_location?
end

_geo_distance排序将产生原始结果中的距离。

sorting by the _geo_distance will yield the distance in the raw results.

推荐答案

排序 _geo_distance 将返回结果中的距离:
http:// www.elasticsearch.org/guide/reference/api/search/sort.html

Sorting by _geo_distance will return the distance in the results: http://www.elasticsearch.org/guide/reference/api/search/sort.html

这篇关于在弹性搜索中计算地理距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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