else part is working fine and data is getting updated in case of promotionID but when it comes to if part my data against correlation id is not getting updated but it get's inserted ,
If I undestand this correctly, the part that's not working is
if "##ERROR CODE" in [message] {
elasticsearch {
...
}
}
If so, that is probably the syntax is a bit misleading. By default the message is the preset field that holds the entire log, so unless you overwrite it that how it stays till the end.
Thing is, if "something" in [message] checks for a literal match, not a regex of any kind, so
if "##ERROR CODE" in [message] {
will work if the message is "##ERROR CODE", but will fail if the message is "##ERROR CODE foo"
You probably want the regex operator for that, like
Edit: As it was pointed out to me by @Badger, the in clause apparently supports substring matching (if the conditional order is value -> field, but not field -> value).
Also, the issue is apparently quite unrelated to what I said above since the document is initially inserted as you said (but I'll keep the post up). Do you get any relevant errors in Logstash?
I used to have If statements in the Logstash output section but have removed them all and use @metadata fields to do the same thing these days. I think it could work for you as well
I would, in the filter section set %{[@metadata][document_id]} to what you want based on whatever conditions you want and use document_id => "%{[@metadata][document_id]}" in the output section.
This is an example from my Logstash filter section
# Adding @metadata needed for index sharding to Filebeat logs
mutate {
copy => {
"[fields][log_prefix]" => "[@metadata][log_prefix]"
"[fields][log_idx]" => "[@metadata][index]"
}
}
If you have the information already in the logs that you want to use for index naming you can assign it as above. If it is not in the logs you can statically set it with e.g. add_field.
if [fields][log_type] == "Promotions"
{
if "TARGET MESSAGEJMS Message Out" in [message] or "SOURCE MESSAGEJMS Message In" in [message]
{
elasticsearch
{
hosts => "localhost:9200"
manage_template => false
index => "elkrft-ind-%{+YYYY.MM.dd}"
action => "update"
document_id => "%{PromotionID}"
doc_as_upsert => true
}
}
else
{
elasticsearch
{
hosts => "localhost:9200"
manage_template => false
index => "elkrft-ind-%{+YYYY.MM.dd}"
action => "update"
document_id => "%{Correlation_Id}"
doc_as_upsert => true
}
}
stdout { codec => rubydebug }
}
}
Questions :-
Tried using if [message] =~ /##ERROR CODE/ but not able to do the same
if "TARGET MESSAGEJMS Message Out" in [message] or "SOURCE MESSAGEJMS Message In" in [message] TRIED THIS but in case of my Error ideally it should go in else loop but logs doesn't get update in case of co-relation id , it get's inserted
3 Summary :- There are 3 logs which i have tried to break one is "IN", one is "OUT" and third one is "ERROR" , In my IN and OUT logs i have field Promo ID and Correlation iD and i am updating WITH key Promo Id but in case of my Error Logs there is no Promo id in my logs and i am updating with key "Coorealtion ID".
4 Not able to find meta data applied in my case , if there's any good video and documentation please help
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.