在elasticsearch中未生成geohash

jgzswidk  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(1)|浏览(345)

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

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的概念搞砸了??救命!!

6ljaweal

6ljaweal1#

根据启用geohash标志的文档,geo\u point索引geohash值。
索引的内容和响应的\u源字段表示的内容有所不同。
响应中的源字段是传递给elasticsearch进行索引的原始json文档。
启用geohash标志时,geo_点类型将使用geohash表示法编制索引,但实际的源文档不会更改
要了解geohash标志如何补充geo\u point type的索引方式,您可以使用fielddata\u 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"
               ]
            }
         }
      ]
   }

相关问题