【问题标题】:Elasticsearch to find places up to some distance from a set of reference pointsElasticsearch 查找距离一组参考点最远的地方
【发布时间】:2020-05-03 15:11:45
【问题描述】:

我需要帮助进行查询,以便使用 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"

【问题讨论】:

  • 到目前为止你有什么想法?我们可以为您指明正确的方向,但不能为您写下所有内容。
  • 我试图更好地解释添加更多信息。
  • 谢谢,好多了。

标签: elasticsearch search geocoding geocode


【解决方案1】:

AFAIK 不幸的是,在 ES 中没有 ST_Distance_Sphere 的替代品。

是否需要重新考虑构建数据的方式——也许是每个place 中最近的n 机构?说,5公里。然后,如果用户需要

地铁站/药店/等大多是固定位置(字面上和比喻上)。他们不会经常更改属性/geoloc/等。当他们这样做时,对附近每个地方的简单更新应该可以解决问题。

【讨论】:

  • 这种方法对@Pierre 有效吗?你最终是如何解决这个问题的?
猜你喜欢
  • 2021-08-20
  • 1970-01-01
  • 2011-08-20
  • 1970-01-01
  • 1970-01-01
  • 2010-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多