gpt4 book ai didi

ruby - 在 Elasticsearch 中计算地理距离

转载 作者:数据小太阳 更新时间:2023-10-29 07:00:18 26 4
gpt4 key购买 nike

我在查询中使用 geo_distance filtertire,它工作正常:

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

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

有没有办法告诉 elasticsearch 在响应中包含它,这样我就不必在 ruby​​ 中为每个结果计算它?

== 更新 ==

我在谷歌群组中的 found the answer:

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

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

最佳答案

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

关于ruby - 在 Elasticsearch 中计算地理距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9290057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com