Trying to update a specific field in elasticsearch through logstash. Is it possible to update only a set of fields through logstash ?
Please find the code below,
filter {
csv {
separator => "|"
columns => ["NAME","ID","COUNTRYNAME","DATE","STATECODE", "G_NAME","G_ID","G_COUNTRYNAME","
G_DATE","G_STATECODE"]
}
ruby {
code => "
hash = event.to_hash
hash.each do |k,v|
if v == nil
event.remove(k)
end
end
"
}
}
We are using the above configuration when we use this the null value field is getting removed instead of skipping null value update.
Sample Complete document log input
John|892|Canada|31-01-2017|QC
Updating a document with null value should not remove the field instead the null value fields should be skipped and the reside with existing date 31-01-2017 value. John|892|Canada||QC
I have updated like this but i am not getting proper results
filter {
csv {
separator => "|"
columns => ["NAME","ID","COUNTRYNAME","DATE","STATECODE", "G_NAME","G_ID","G_COUNTRYNAME","
G_DATE","G_STATECODE"]
}
mutate {
update => { "COUNTRYNAME" => "qqqqqqq" }
}
EDIT: I for to mention that you need to generate your own document_id and set that. So in order to update a existing document you need to set a id on the initial document and reuse that. (bad example: ie: email_address) or query ES for the document_id using the logstash-filter-elasticsearch plugin.
It will look something like this.
output {
elasticsearch {
host => 'your es host'
action => 'update'
document_id => 'your generated document id'
index => 'your index name
}
}
This is what we already have. When we try to update it the entire document is getting updated instead of updating a single field. How to achieve this ?
With this configuration you should be able to update a single field or any fields send to ES.
For example, you have field A, B and C and you send a doc with a updated field A it leaves B and C alone and it updates A and it will update you document @Version (but thats arbitrary)
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.