ElasticSearch映射geo-point字段报错求助:No handler for type [geo-point]
解决Elasticsearch geo-point类型映射错误的问题
首先,你遇到的错误根源非常明确:字段类型名拼写错误!Elasticsearch中官方定义的地理点类型是geo_point(下划线连接),而非你使用的geo-point(横杠连接),这就是系统提示"No handler for type [geo-point]"的原因。
接下来我会分两种常见场景,一步步教你正确配置映射,适配你的逗号分隔坐标字符串(比如"12.35,48.64"):
场景1:索引无数据或可重新导入数据
这种情况操作最简单,直接重建索引并配置正确映射即可:
- 先删除已存在的错误索引(如果有的话):
DELETE your_index_name
- 创建新索引,将
latlong字段指定为geo_point类型(Elasticsearch支持直接解析逗号分隔的坐标字符串):- 若你使用Elasticsearch 7.x及以上版本(已移除映射类型):
PUT your_index_name { "mappings": { "properties": { "latlong": { "type": "geo_point" } } } }- 若你使用6.x及更早版本(需指定映射类型,比如
docs):
PUT your_index_name { "mappings": { "docs": { "properties": { "latlong": { "type": "geo_point" } } } } } - 现在导入你的数据,逗号分隔的坐标字符串会被自动解析为地理点,之后就能在Kibana中正常实现地图可视化了。
场景2:索引已有数据,无法删除重建
如果索引中已经存储了数据,Elasticsearch不允许直接修改字段类型,需要通过_reindex API迁移数据到新索引:
- 先创建一个带有正确
geo_point映射的新索引(参考场景1的创建步骤,命名为your_index_new) - 执行数据迁移,将旧索引的数据同步到新索引:
POST _reindex { "source": { "index": "your_index_name" }, "dest": { "index": "your_index_new" } }
- (可选)为了让应用无需修改索引名称,可以将新索引设置为原索引的别名:
POST _aliases { "actions": [ { "remove": { "index": "your_index_name", "alias": "your_index_name" } }, { "add": { "index": "your_index_new", "alias": "your_index_name" } } ] }
额外注意事项
要留意坐标的顺序:Elasticsearch解析逗号分隔的字符串时,默认规则是纬度在前,经度在后(格式为"lat,lon")。如果你的数据是经度在前、纬度在后(比如"12.35,48.64"中12.35是经度),需要调整数据格式,比如改成数组[12.35, 48.64](数组格式为[lon, lat]),或者在映射中添加ignore_malformed: false来验证数据正确性,避免地图上的位置出现偏移。
内容的提问来源于stack exchange,提问作者Nate
相关产品推荐
相关产品推荐

