[英]Logstash output is incorrect
我是logstash和elasticsearch的新手。 我使用logstash讀取數據庫更新並存儲到elasticsearch中以便快速搜索。 以下是我的logstash配置文件(countries.conf)。
input {
jdbc {
jdbc_driver_library => "/home/vagrant/postgresql-9.4-1201.jdbc4.jar"
jdbc_driver_class => "org.postgresql.Driver"
jdbc_connection_string => "jdbc:postgresql://192.168.10.123:5432/myDB"
jdbc_user => "myuser"
jdbc_password => "mypassword"
schedule => "* * * * *"
statement_filepath => "/home/vagrant/countries.sql"
last_run_metadata_path => "/home/vagrant/logstash/countries.log"
}
}
output {
elasticsearch {
index => "myIndex"
document_type => "countries"
document_id => "%{id}"
hosts => "localhost:9200"
}
stdout { codec => json_lines }
}
而我的countries.sql文件如下
SELECT json.id as id,
row_to_json(json.*) AS _source
FROM (
SELECT id, created, modified, name, capital, iso_alpha2, iso_alpha3
FROM countries
) as json
我使用以下命令運行配置文件
sudo /opt/logstash/bin/logstash -f /home/vagrant/countries.conf
在stdout上輸出以上命令如下: -
Settings: Default pipeline workers: 1
Pipeline main started
{"_id":6,"_source":{"type":"json","value":"{\"id\":6,\"created\":\"2013-02-07T10:11:00\",\"modified\":\"2016-04-29T11:15:40.329\",\"name\":\"Andorra\",\"capital\":\"Andorra la Vella\",\"iso_alpha2\":\"AD\",\"iso_alpha3\":\"AND\"}"},"@version":"1","@timestamp":"2016-05-02T10:08:00.931Z"}
正如您在上面的輸出中所看到的,_source字段中的json字符串已更改。 理想情況下應該如下所示
{"_id":6,"_source":{\"id\":6,\"created\":\"2013-02-07T10:11:00\",\"modified\":\"2016-04-29T11:15:40.329\",\"name\":\"Andorra\",\"capital\":\"Andorra la Vella\",\"iso_alpha2\":\"AD\",\"iso_alpha3\":\"AND\"},"@version":"1","@timestamp":"2016-05-02T10:08:00.931Z"}
Logstash正在改變我的json字符串。 它正在添加類型:“json”一個額外的字段,並在值字段中添加我的實際json sting。 我越過了檢查數據庫。 我的SQL查詢正確地以我需要的格式返回json字符串。
有人可以讓我知道我錯過了什么嗎? 或者可以指導我正確的方向?
提前致謝!
檢查elasticsearch中的日志。 我認為主要是因為你在stdout中使用codec => json_lines
,這就是為什么要type=>json
的原因。 Elasticsearch記錄沒有類型字段。
如果elasticsearch中的日志也有type => json,請使用mutate刪除該字段。
filter {
mutate {
remove_field => [ "type" ]
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.