我们使用Elasticsearch来索引无模式数据.问题是,大多数我们要编制索引的条目包含类似领域"longitude","latitude","lat"或"long".
索引数据的最佳方法是什么,因此字段类型允许使用地理距离过滤器进行搜索?
非常感谢.
我知道你发布这篇文章已有一段时间了,但万一有人像我一样偶然发现它,这里有一些方法可以做到.
在我们的例子中,我们需要一个动态半径,所以这里是我们的映射:
"mappings": {
"mygeopoints": {
"properties": {
"geopoint": {
"type": "geo_point",
"lat_lon" : true
},
"radius": {
"type": "long"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我们的文档使用SQL查询编制索引,如下所示:
SELECT label, (lat || ',' || lon) as geopoint, radius FROM points;
Run Code Online (Sandbox Code Playgroud)
我们将地缘点作为一个字符串发送,其中包含由昏迷分隔的纬度和经度.
要现在搜索点,您可以使用geo_distance过滤器:
"filter" : {
"geo_distance" : {
"geopoint" : [ 5.7, 43.5 ],
"distance" : "15km"
}
}
Run Code Online (Sandbox Code Playgroud)
尽管如此,我们需要一个动态范围,所以除了使用脚本过滤器之外我们没有找到任何其他解决方案.
"filter" : {
"script" : {
"script" : "!doc['geopoint'].empty && doc['geopoint'].distanceInKm(43.5,5.7) <= doc['radius'].value"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6148 次 |
| 最近记录: |