【问题标题】:elasticsearch_dsl search by geo location distance and get results and distanceelasticsearch_dsl 按地理位置距离搜索并获取结果和距离
【发布时间】:2018-05-02 07:28:53
【问题描述】:

我有一个保存商店位置数据的索引。

当使用 python 的elasticsearch_dsl 时,我想找到给定位置最近的商店,按距离排序。既然ES已经计算了距离,那么是否可以将其作为搜索结果的一部分?

可以在单个查询中使用elasticsearch_dsl 来实现吗?还是我必须对位置 lat,lon 进行后处理并手动计算距离?

谢谢。

【问题讨论】:

    标签: python elasticsearch elasticsearch-dsl


    【解决方案1】:

    您可以sort by distance 并在结果命中中获得计算出的距离。

    例如:

    s = Search().sort(
        {
            "_geo_distance" : {
                "location" : {"lat": 40, "lon": -70},
                "order" : "asc",
                "unit" : "km",
                "distance_type" : "arc"
            }
        }
    )
    

    【讨论】:

    • 该解决方案使用elasticsearch_dsl
    • 酷,很高兴它有帮助!
    猜你喜欢
    • 2012-08-03
    • 2022-01-24
    • 2012-06-20
    • 2011-08-26
    • 2012-07-18
    • 2012-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多