pho*_*oet 7 ruby geolocation elasticsearch
我在我的查询中使用带轮胎的geo_distance过滤器,它工作正常:
search.filter :geo_distance, :distance => "#{request.distance}km", :location => "#{request.lat},#{request.lng}"
Run Code Online (Sandbox Code Playgroud)
我希望结果会以某种方式包含我用于过滤器的地理位置的计算距离.
有没有办法告诉elasticsearch在响应中包含它,以便我不必为每个结果在ruby中计算它?
==更新==
我在谷歌小组中找到了答案:
search.sort do
by "_geo_distance", "location" => "#{request.lat},#{request.lng}", "unit" => "km" if request.with_location?
end
Run Code Online (Sandbox Code Playgroud)
按原样排序_geo_distance会产生原始结果中的距离.