ES查找高德地图两点间路径经过的点(geohash)

问题

希望查找到我从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/
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值