1

我创建了一个索引,如下所示:

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查询结果中某处的地理哈希字符串,我可以用它来查询未来的位置点。还是我对 geohash+ES 的概念搞砸了??帮助!!

4

1 回答 1

1

根据在 geo_point 中启用geohash标志的文档索引geohash值。

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

响应中的_source字段是传递给 elasticsearch 索引的原始原始 json 文档。

当您启用 geohash 标志时,geo_point 类型将使用 geohash 表示进行索引,但实际源文档不会更改

要了解 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"
               ]
            }
         }
      ]
   }
于 2015-05-25T23:07:18.633 回答