I wanna run ruby script for calculating the diference between documents.here is my script
input {
elasticsearch {
hosts => "http://192.168.55.213:9200"
index => "test_index"
query => '{"sort": [{"logTimestamp": {"order": "asc"}}]}'
}
}
filter {
ruby {
init => "@@map = {}"
code => "
map['timeDifference']= (Time.parse(event.get('logTimestamp')).to_f - Time.parse(map['previousTime']).to_f).round(4);
event.set('timeDifference', map['timeDifference']);
map['previousTime'] = event.get('logTimestamp');
event.set('previousTime', map['previousTime']);
"
}
mutate {
remove_field => ["@version","@timestamp"]
}
}
output {
elasticsearch {
document_id => "%{logTimestamp}"
document_type => "test_index"
index => "test_index"
codec => "json"
hosts => ["192.168.55.213:9200"]
}
}
But when I am trying to execute script its giving me error as
undefined local variable or method `map' for #LogStash::Filters::Ruby:0x3b42c4a8
Also I wanna hold the logTimestamp of first document and calculate the difference when second record is received and finally store it in second record.How can I calculate the difference?