【发布时间】: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