I'm using this plugin as output for my logstash logs.
I need to use the upsert function to check if a row exists then update, if it doesn't exist then simply add.
I'm using PostgreSQL as db and it supports the usage of UPSERT, very good described here. As input, the logs are coming from elasticsearch.
The problem with my configuration is that I correctly add new rows in my table but cannot update an existing one.
Here's my configuration :
jdbc {
driver_jar_path => '/home/vittorio/Downloads/postgresql-42.1.1.jre6.jar'
connection_test => false
connection_string => 'jdbc:postgresql://127.0.0.1:5432/postgres'
statement => ["
INSERT INTO userstate VALUES(?,?,?,?,?) on conflict (username)
do update set (business_name, iban, status, timestamp) = ('%{[resource][response_attributes][business_name]}','%{[resource][response_attributes][iban]}','%{[resource][response_attributes][status]}','%{@timestamp}')
where userstate.username = '%{[request][username]}';", "%{[request][username]}","%{[resource][response_attributes][business_name]}","%{[resource][response_attributes][iban]}","%{[resource][response_attributes][status]}","%{@timestamp}"
]
username => "myuser"
password => "mypass"
}
Am I doing something wrong? thanks