Elasticsearch是指在距离一组参考点一定距离的地方进行搜索



我需要帮助进行查询,以便使用弹性搜索找到距离某些参考点不到1000米的地方。I.E.:哪些药店距离用户定义的地铁站不到1000米。我有它们的纬度和经度值。

我在弹性搜索上发现了一些这种类型搜索的例子,但所有这些都考虑了滤波器上的一组静态参考点(硬编码的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的替代方案。

是否需要重新思考您构建数据的方式——也许是每个place中最近的n机构?比如说,5公里。然后,如果用户要求<=1公里,你可以过滤掉太远的。

地铁站/药店等大多是固定的位置(字面上和比喻上都是(。他们不会经常更改属性/geoloc等。当他们这样做的时候,对附近的每个地方进行简单的更新就可以了。

最新更新