2017-05-17 5 views
0

私はthisプラグインをログ出力ログに出力しています。jdbc出力プラグインlogstash UPSERT関数を使用

行が存在するかどうかを確認するためにupsert関数を使用する必要があります。存在しない場合は単に追加してください。

私はdbとしてPostgreSQLを使用しており、UPSERTの使用方法をサポートしています。非常に良い説明はhereです。入力として、ログはelasticsearchから来ています。

私の設定の問題は、テーブルに新しい行を正しく追加するが、既存の行を更新できないことです。ここで

は私の設定です:

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" 
} 

私が何か間違ったことをやっていますか? おかげ

答えて

0

私はそれを自分で動作させるためにうまく管理し、これは私がこれまで何をやったかである:

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) = (?,?,?,?) 
      where userstate.username = ?" 
      , "%{[request][username]}","%{[resource][response_attributes][business_name]}","%{[resource][response_attributes][iban]}","%{[resource][response_attributes][status]}","%{@timestamp}","%{[resource][response_attributes][business_name]}","%{[resource][response_attributes][iban]}","%{[resource][response_attributes][status]}","%{@timestamp}","%{[request][username]}" 

      ] 
      username => "myusername" 
      password => "mypass" 

     } 

は基本的に、私は?代わりの%{[request][username]}を使用してwhere文を変更して、それぞれをマッピングしました?に対応する値をログから取得します。わかった、それは昏睡状態の後でかなり長いものですが、これが動作するように私が見つけた唯一の方法です。誰かがそれを行うためのより良い方法を知っている場合は、私に知らせてください。

ありがとうございます

関連する問題