我创建了如下索引:
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/