我在 ElasticSearch 中有一个索引,其中包含以下字段
EmpId | Name | Age | Title
它包含一些数据,我需要添加其他字段,如
Address | City | MobileNumber
这些额外的列存在于 CSV 文件中
EmpId| Address | City | MobileNumber
下面是logstash.conf
input {
file {
path => "D:/data.csv"
start_position =>"beginning"
sincedb_path =>"index/test1"
}
}
filter {
csv {
separator => ","
columns => ["EmpId","Address","City","MobileNumber"]
}
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "myindex"
document_id => "%{EmpId}"
}
stdout {}
}
现在当我运行这个文件时,旧的字段被删除,我只能看到新的列 “EmpId”、“地址”、“城市”、“手机号码”
如何在添加新字段的同时保留旧字段?
答案 0 :(得分:0)
将这两行添加到您的 elasticsearch
输出部分:
action => "update"
doc_as_upsert => true
所以整个输出块将是:
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "myindex"
document_id => "%{EmpId}"
action => "update"
doc_as_upsert => true
}
}
进一步阅读:
doc_as_upsert
设置)[编辑:在发现这完全有效后完全重写。我的罪过]