elasticsearch - Elasticsearch 未生成Geohash

标签 elasticsearch geolocation geospatial geohashing

我创建了如下索引:

POST /cabtrails
{
  "settings" :
{
  "number_of_shards" : 3,
  "number_of_replicas" : 1
 },
"mappings" : {
"cabtrail" :{
  "properties" : {
        "location": {
            "type":               "geo_point",
            "geohash_prefix":     true, 
            "geohash_precision":  "5m" 
          },
          "capture_time": {
                "type" : "long"

            },
          "client_id": {
            "type" : "long"

          }
       }
     }
   }
}

它工作正常,并创建了一个索引。

我输入了一个样本文档为:
POST cabtrails/cabtrail
{
    "capture_time": 1431849367077,
    "client_id": 865527029812357,
    "location": "13.0009316,77.5947316"
}

这也很好。
在这里,我期望ElasticSearch将生成我可以使用的geohash字段/条目。

但是,当我查询时,我得到了:
GET cabtrails/_search
{
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 3,
      "successful": 3,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "cabtrails",
            "_type": "cabtrail",
            "_id": "AU2LrEaze2aqxPjHm-UI",
            "_score": 1,
            "_source": {
               "capture_time": 1431849367077,
           "client_id": 865527029812357,
           "location": "13.0009316,77.5947316"
        }
     }
      ]
   }
}

我期望查询结果中某处有一个像u10hbp这样的geo-hash字符串,我可以用它来查询将来的位置点。还是我的geohash + ES概念搞砸了??救命!!

最佳答案

根据geo_point索引中启用document的geohash标志,索引geohash值。

索引内容和响应的_source字段代表什么有所不同。

响应中的_source字段是原始原始json文档,已将其传递以索引到Elasticsearch。

启用geohash标志时,使用geohash表示法对geo_point类型建立索引,但实际的源文档未更改

要了解geohash标志如何补充geo_point类型的索引方式,您可以使用fielddata_fields api:

对于上面的示例,这些行看起来像:

**Query**
POST cabtrails/_search
{

    "fielddata_fields" :["location","location.geohash"]
}

响应:
"hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "cabtrails",
            "_type": "cabtrail",
            "_id": "AU2NRn_OsXnJTKeurUsn",
            "_score": 1,
            "_source": {
               "capture_time": 1431849367077,
               "client_id": 865527029812357,
               "location": "13.0009316,77.5947316"
            },
            "fields": {
               "location": [
                  {
                     "lat": 13.0009316,
                     "lon": 77.5947316
                  }
               ],
               "location.geohash": [
                  "t",
                  "td",
                  "tdr",
                  "tdr1",
                  "tdr1v",
                  "tdr1vw",
                  "tdr1vww",
                  "tdr1vwwz",
                  "tdr1vwwzb",
                  "tdr1vwwzbm"
               ]
            }
         }
      ]
   }

关于elasticsearch - Elasticsearch 未生成Geohash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30441723/

相关文章:

elasticsearch - 如何获得使用DSL的精确匹配

python - Django Haystack搜索html标签会返回所有帖子

elasticsearch - 使用 NEST 在 ElasticSearch 上批量更新

elasticsearch - 在Elasticsearch模板中创建Geoip字段

javascript - 如何在没有警报消息(iOS)的情况下获得 webview 中的地理定位权限?

r - R : The subscript var has the wrong type quosure/formula. It must be numeric or character中的错误

elasticsearch - Elasticsearch 更新脚本以返回值

geolocation - 最佳 IP 国家数据库

javascript - turf.booleanOverlap 意外结果

mysql - 如何在 MySQL 中反序列化多边形数据以获取纬度/经度?