弹性搜索中未生成 Geohash
Geohash not generated in Elastic search
我创建了一个索引如下:
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 field/entry。
但是,当我查询时,我得到这个:
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的概念搞砸了??求助!!
根据 document 在 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"
]
}
}
]
}
我创建了一个索引如下:
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 field/entry。
但是,当我查询时,我得到这个:
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的概念搞砸了??求助!!
根据 document 在 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"
]
}
}
]
}