Elasticseach无法将非对象映射与对象映射合并



不知何故,可以在Elasticsearch映射中定义地理点字段类型并导入数据,但不能两者兼而有之。在JSON数据中,位置字段如下

"location": { 
"lat": 41.12,
"lng": -71.34
}

因为我们需要";lon";而不是";lng";我们使用这个";突变";在Logstash配置中过滤以重命名字段:

mutate {
rename => {
"[location][lng]" => "[location][lon]"
}
}

如果我们不使用映射,那么Elasticsearch会自动为位置字段使用以下映射并导入数据

"location": {
"properties": {
"lat": {
"type": "float"
},
"lon": {
"type": "float"
}
}
}

到目前为止还不错。但是,如果我现在在创建索引时在Elasticsearch映射中使用"geo_point",那么我就无法再导入任何数据,因为我在Logstash中收到错误消息">无法将非对象映射[location]与对象映射合并",如果我们试图更改映射,就会发生这种情况。但在这里,映射已经用于创建索引:

"mappings":{
"properties":{
"location": {
"type": "geo_point",
"ignore_malformed": "true",
},
}
}

显然,Logstash和Elasticsearch认为映射中类型为geo_point的字段location不是对象,而该位置的JSON数据是对象。

虽然使用这种映射无法在Logstash中导入数据,但我可以通过将文档保存在Kibana DEV工具中

PUT geo-test/_doc/1
{
"title": "Geo-point test",
"location": { 
"lat": 41.12,
"lon": -71.34
}
}

如何使用地理点映射将数据导入Logstash?(我使用的是Elasticsearch 7.9.1版和Logstash 7.12.0版,包括S3输入插件和Elasticearch输出插件(

出现此错误的原因是在elasticsearch输出中指定了不同的document_type。只需删除下面强调的行,它将按照您的预期工作:

elasticsearch {
hosts => [ "${ES_DOMAIN_NAME}:443" ]
healthcheck_path => "/"
ilm_enabled => false
ssl => true
index => "${ES_INDEX}"
document_type => "json"         <--- remove this line
}

您安装的映射适用于默认文档类型,即_doc而非json

最新更新