2015-05-25 64 views
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的概念搞砸了?幫幫我!!

回答

1

作爲每document使地理散列標誌geo_point索引地理散列值。

索引的內容與響應中的內容有什麼不同。

_source字段中的響應是原始的原始json文檔,它被傳遞給索引到elasticsearch。

當您啓用地理散列標誌geo_point類型是使用地理散列代表,但實際的源文件不會被改變

要獲得地理散列標誌是如何補充的方式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" 
       ] 
      } 
     } 
     ] 
    }