我需要帮助做一个查询,以便使用elasticsearch找到哪些地方距离一些参考点不到1000米。例如:哪些药店距离用户定义的地铁站不到1000米。我有它们的经纬度值。
我在elasticsearch上找到了一些这种搜索类型的例子,但所有这些例子都是考虑到过滤器上的一组静态参考点(硬编码纬度和经度)。
补充更多信息。
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.locationorigin的值是固定的,但我需要这个基于参考索引的值。
在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 &不幸的是,没有其他的方法可以替代。ST_Distance_Sphere
在ES中。
将需要重新思考你的数据结构方式--也许最接近你的数据结构。n
各个 place
? 比如,5公里。那么,如果用户要求<=1km,你可以过滤掉太远的。
地铁站drugstoresetc大多是固定的位置(包括字面的&形象的)。它们不会经常改变属性geolocetc。当它们发生变化时,简单的更新每个附近的地方应该可以做到这一点。