elasticsearch查询的单位,用于获取从任意点到地质点的距离

pgky5nke  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(2)|浏览(478)

我有一个django项目,它使用elasticsearch6.5.3对商店中的产品进行索引,并将地点作为地理点。我试着查询这个索引,还计算了任意点之间的距离,说用户的位置到每个哦这些结果。
我正在使用elasticsearch\u dsl,我的代码如下所示:

search_query = search_query.script_fields(distance={
'script':{
    'inline':"doc['location'].arcDistance(params.lat, params.lon)", 
    'params': {
        'lat':user_loc.lat, 
        'lon':user_loc.lon
        }
    }
})
for result in search_query.execute():
    print(result.distance)

这给了我如下的值:

[123456.456879123]

但我不确定它的单位。通过使用和在线距离计算器https://www.nhc.noaa.gov/gccalc.shtml,这给了我约123公里的距离,看起来值是米。
所以:
1我在哪里可以找到关于它的单位的确切答案?
请告诉我这些方法的相关文档。我还想知道是否有办法指定方法调用中结果的预期单位。
2在python中有更好的方法吗?

gdx19jrr

gdx19jrr1#

这些单位是由政府归还的 arcDistance 方法在脚本中提供值。
该地理点场与所提供纬度/经度的弧距离(单位:米)
无痛文件留下了很多需要改进的地方(6.5中似乎没有关于这种方法的文件)。以上引述来自:https://www.elastic.co/guide/en/elasticsearch/reference/2.3/modules-scripting.html
此外,他们提到 arcDistance 此处计算米数:https://www.elastic.co/guide/en/elasticsearch/reference/5.5/breaking_50_scripting.html

mspsb9vt

mspsb9vt2#

我不确定确切的python api,但elasticsearch有地理距离查询:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
在:https://github.com/elastic/elasticsearch-dsl-py/issues/398 有一个使用es api的python示例:

MyDocType.search().filter(
'geo_distance', distance='1000m', location={"lat": "40", "lon": "-74"}
)

“地理距离”查询是获取索引到elasticsearch的两个地理点之间距离的最简单方法。我认为你不需要使用脚本来实现这一点。
关于距离单位,如您所怀疑的,默认值是米。发件人:https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#distance-单位
在需要指定距离的任何位置(如地理距离查询中的距离参数),如果未指定,则默认单位为米。

相关问题