我有一个elk堆栈,我想解析一个csv,其中一个字段包含json但我遇到了一个logstash错误。所以我需要知道如何将csv中的json字段解析为elasticssearch。
10:54:20.220 [[main]> worker1] WARN logstash.filters.csv - 错误 解析csv {:field =>“message”,:source =>“431 | 2017-01-26 10:08:57 | example@example.com |的firstName | lastName的| GBP | GB | 2015年6月14日 07:16:39 | 43.88 | 2017年1月24日 13:45:28 | F | {\ “18272 \”:{\ “19208 \”:\ “1 \” \ “19210 \”:\ “1 \”},\ “18218 \”:{\” 19099 \ “:\” 1 \ “},\” 18783 \ “:{\” 19249 \ “:\” 2 \ “}} | 5 | GBP”, :异常=>#}
csv中的示例行如下所示,因为您可以看到它是分隔符分隔符。
431 | 2017年1月26日 10:08:57 | example@example.com |的firstName | lastName的| GBP | GB | 2015年6月14日 07:16:39 | 43.88 | 2017年1月24日 13:45:28 | F | {\ “18272 \”:{\ “19208 \”:\ “1 \” \ “19210 \”:\ “1 \”},\ “18218 \”:{\” 19099 \ “:\” 1 \ “},\” 18783 \ “:{\” 19249 \ “:\” 2 \“}} | 5 | GBP
我的配置如下。
input {
file {
path => "/etc/logstash/files/*.csv"
start_position => "beginning"
}
}
filter {
csv {
separator => "|"
columns => ['userId', 'profileUpdated', 'email', 'lastName', 'firstName', 'userCurrency', 'billingCountry', 'registeredDate', 'cartValue', 'cartUpdated', 'kitInCart', 'cart' 'itemsInCart' ,'cartCurrency']
}
json {
source => 'cart'
}
date {
match => [ "registeredDate", "YYYY-MM-dd HH:mm:ss" ]
}
}
output {
stdout {
codec => rubydebug
}
elasticsearch {
hosts => "elasticsearch:9200"
index => "users"
}
}
如您所见,我的购物车字段是json。
答案 0 :(得分:2)
我将此添加到我的csv filterconfig文件中并且它可以正常工作。
quote_char => "'"