Elasticsseach 无法将非对象映射与对象映射合并
Elasticsseach can’t merge a non object mapping with an object mapping
可以通过某种方式在 Elasticsearch 映射中定义 geo-point field type 并导入数据,但不能同时进行。在 JSON 数据中,位置字段如下所示
"location": {
"lat": 41.12,
"lng": -71.34
}
因为我们需要“lon”而不是“lng”,所以我们在 Logstash 配置中使用这个“mutate”过滤器来重命名字段:
mutate {
rename => {
"[location][lng]" => "[location][lon]"
}
}
如果我们不使用映射,那么 Elasticsearch 会自动为位置字段使用以下映射并导入数据
"location": {
"properties": {
"lat": {
"type": "float"
},
"lon": {
"type": "float"
}
}
}
到目前为止一切顺利。但是,如果我现在在创建索引时在 Elasticsearch 映射中使用“geo_point”,那么我将无法再导入任何数据,因为我收到错误消息“无法合并非对象映射 [ location] 与对象映射 ” 在 Logstash 中 can happen 如果我们尝试更改映射。但是这里映射已经用于创建索引:
"mappings":{
"properties":{
"location": {
"type": "geo_point",
"ignore_malformed": "true",
},
}
}
显然 Logstash 和 Elasticsearch 将映射中具有类型 geo_point
的字段 location
视为不是对象的东西,而此位置的 JSON 数据是一个对象。
虽然无法使用此映射将数据导入 Logstash,但我可以像这样将文档保存在 Kibana DEV Tools 中
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 输入插件和 Elasticsearch 输出插件)
您收到此错误的原因是您在 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
。
可以通过某种方式在 Elasticsearch 映射中定义 geo-point field type 并导入数据,但不能同时进行。在 JSON 数据中,位置字段如下所示
"location": {
"lat": 41.12,
"lng": -71.34
}
因为我们需要“lon”而不是“lng”,所以我们在 Logstash 配置中使用这个“mutate”过滤器来重命名字段:
mutate {
rename => {
"[location][lng]" => "[location][lon]"
}
}
如果我们不使用映射,那么 Elasticsearch 会自动为位置字段使用以下映射并导入数据
"location": {
"properties": {
"lat": {
"type": "float"
},
"lon": {
"type": "float"
}
}
}
到目前为止一切顺利。但是,如果我现在在创建索引时在 Elasticsearch 映射中使用“geo_point”,那么我将无法再导入任何数据,因为我收到错误消息“无法合并非对象映射 [ location] 与对象映射 ” 在 Logstash 中 can happen 如果我们尝试更改映射。但是这里映射已经用于创建索引:
"mappings":{
"properties":{
"location": {
"type": "geo_point",
"ignore_malformed": "true",
},
}
}
显然 Logstash 和 Elasticsearch 将映射中具有类型 geo_point
的字段 location
视为不是对象的东西,而此位置的 JSON 数据是一个对象。
虽然无法使用此映射将数据导入 Logstash,但我可以像这样将文档保存在 Kibana DEV Tools 中
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 输入插件和 Elasticsearch 输出插件)
您收到此错误的原因是您在 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
。