elasticsearch - Elasticsearch查找距一组引用点最远距离的位置

标签 elasticsearch search geocoding geocode

我需要帮助进行查询,以便使用Elasticsearch查找距某些引用点不到1000米的地方。 I.E .:哪些药房距离用户定义的地铁站不到1000米。我有他们的经度和纬度值。

我在elasticsearch上找到了这种搜索类型的一些示例,但所有示例都在考虑过滤器(硬编码的lat和lng)上的一组静态引用点。

添加更多信息:

GET /places
{
  "places" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "location" : {
          "type" : "geo_point"
        },
        "name" : {
          "type" : "text"
        }
      }
    }
}

GET /references
{
"references" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "location" : {
          "type" : "geo_point"
        },
        "name" : {
          "type" : "text"
        }
      }
    }
}

我试图创建一个搜索请求,在这里我可以根据引用索引上的文档列表来选择场所索引上的文档。大多数示例仅演示如何搜索这样的文档:
GET /places/_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "1000m",
                    "pin.location" : {
                        "lat" : 40,
                        "lon" : -70
                    }
                }
            }
        }
    }
}

上面示例中的值pin.location / origin是固定的,但是我需要基于引用索引。

在MySQL中应该是这样的:
select pl.latitude, pl.longitude from places as pl
where exists (
select rf.id from references as rf where ST_Distance_Sphere(
        point(pl.longitude, pl.latitude),
        point(rf.longitude, rf.latitude)
    ) < 1000 and rf.name = "subway"
) and pl.name = "drugstore"

最佳答案

AFAIK不幸的是,ES中没有替代ST_Distance_Sphere的选项。

是否需要重新考虑数据结构的方式-也许每个n的最近place机构?说5公里然后,如果用户要求<= 1km,则可以滤除距离太远的距离。

地铁站/药店/等大多是固定的位置(从字面上和象征意义上来说)。他们不经常更改property / geoloc / etc。当他们这样做时,只需对附近的每个地方进行简单更新即可解决问题。

关于elasticsearch - Elasticsearch查找距一组引用点最远距离的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61576765/

相关文章:

elasticsearch - 具有累积值的 Kibana 直方图意外线曲线

java - 用户搜索功能使用 Java 驱动程序查询 MongoDB 中的数据

mysql - Sphinx 索引器“无错误”错误

google-maps - Jersey /根西岛的谷歌地图 API?

elasticsearch - 结合使用精确的前缀/匹配短语前缀查询和Ngram筛选器

python - 无法检索链接和子链接

javascript - Google 版本 3 map 地理编码器,单击或拖动标记时获取标记图层的坐标

google-maps - 城市 Geojson 多边形数据库/库或 API

elasticsearch - 嵌套计数查询

java - 文件搜索时出现空指针异常