问题
希望查找到我从A点行驶到B点,中间路过的服务区,服务区点已经落在了ES当中
可以使用ES GeoHash网格聚合, 但是他是一个矩形的方式来搜索范围,而高德地图的行驶轨迹并不是直线行驶的。所以希望使用geohash来解决这个问题
ES执行过程
## 查询索引结构
GET points/_mapping{"points_v1" : {"mappings" : {"station_applist" : {"properties" : {"geoHashStr" : {"type" : "keyword"},"location" : {"type" : "geo_point"}}}}
}
## 数据结构
GET points/points/_search
{"query": {"regexp": {"geoHashStr": "((wt5qb)|(wtmbv)).{5,7}"}}
}{"took" : 5,"timed_out" : false,"_shards" : {"total" : 5,"successful" : 5,"skipped" : 0,"failed" : 0},"hits" : {"total" : 3,"max_score" : 1.0,"hits" : [{"_index" : "points_v1","_type" : "points","_id" : "1","_score" : 1.0,"_source" : {"id" : 1,"location" : {"lat" : 29.340052,"lon" : 117.104937},"geoHashStr" : "wt5qbv1nny"}},{"_index" : "points_v1","_type" : "points","_id" : "3","_score" : 1.0,"_source" : {"id" : 5,"location" : {"lat" : 29.687215,"lon" : 120.82586},"geoHashStr" : "wtmbvkqsw9"}},{"_index" : "points_v1","_type" : "points","_id" : "5","_score" : 1.0,"_source" : {"id" : 5,"location" : {"lat" : 29.339229,"lon" : 117.104165},"geoHashStr" : "wt5qbv09ku"}}]}
}
正则表达式意义
希望查询到以 geohash前五位为指定值的geohash对应的点
通过高德地图根据两点得到两点路径周边的点,然后根据然后转换为geohash值,根据geohash的长短,来确定搜索范围。然后再es中查询到匹配的点
-
((wt5qb)|(wtmbv))\w{5,7}
这种方式 在正则表达式测试工具可以通过,不知道为什么es无法通过 -
((wt5qb)|(wtmbv)).{5,7}
测验可以达到所要的目的,可以前五位数字在指定的集合当中
GEOHASH长度与范围关系
参考文档:
- https://www.cnblogs.com/feiquan/p/11380461.html
- http://doc.codingdict.com/elasticsearch/153/