我需要帮助进行查询,以便使用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"
答案 0 :(得分:0)
AFAIK,很遗憾,ES中没有ST_Distance_Sphere
替代品。
是否需要重新考虑数据的结构方式-也许每个n
中最近的place
个机构?说5公里然后,如果用户要求<= 1公里,则可以过滤掉距离太远的地方。
地铁站/药店/等大多是固定的位置(无论从字面上还是在形象上)。他们不经常更改property / geoloc / etc。当他们这样做时,只需对附近的每个地方进行简单更新即可解决问题。