codecamp

Elasticsearch Geohashe映射

Geohashes 映射

首先,你需要确定你需要什么样的精度。 虽然你也可以使用12级的精度来索引所有的地理坐标点,但是你真的需要精确到数厘米的精度吗? 如果你把精度控制在一个实际一些的值,比如 1km,那么你可以节省大量的索引空间:


PUT /attractions
{
  "mappings": {
    "restaurant": {
      "properties": {
        "name": {
          "type": "string"
        },
        "location": {
          "type":               "geo_point",
          "geohash_prefix":     true, <1>
          "geohash_precision":  "1km" <2>
        }
      }
    }
  }
}
  • 将 `geohash_prefix` 设为 `true` 来告诉 Elasticsearch 使用指定精度来做 geohash 前缀索引。
  • 精度描述可以是一个具体数字,表示 geohash 的长度,也可以是一个距离。精度设为 `1km`表示geohash长度是 `7`。

通过如上设置,geohash前缀为 1-7 的部分将被索引,所能提供的精度大约在150米。

Elasticsearch Geohashe
Elasticsearch Geohash单元过滤器
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }