elasticsearch - logstash remove_field 无法将 csv 上传到 elasticsearch
问题描述
我正在使用elasticsearch、kibana 和logstash 6.0.1。
我希望通过 logstash 将 csv 数据上传到 elasticsearch 并删除字段(路径、@timestamp、@version、主机和消息)。我在下面显示 logstash.conf 和 emp.csv 文件。如果我不使用 remove_field 指令但我需要,上传将起作用。此外,未创建索引。
logstash.conf:
input {
file {
path => "e:\emp.csv"
start_position => "beginning"
}
}
filter {
csv {
separator => ","
columns => ["code","color"]
remove_field => ["path", "@timestamp", "@version", "host", "message"]
}
mutate {convert => ["code", "string"]}
mutate {convert => ["color", "string"]}
}
output {
elasticsearch {
hosts => "http://localhost:9200"
index => "emp5"
user => "elastic"
password => "password"
}
stdout {}
}
emp.csv:
1,blue
2,red
在这种情况下缺少什么?
解决方案
在您的csv
文件中,您尝试删除的数据不可用。
而是尝试删除例如path
和host
字段:
(...)
filter {
csv {
separator => ","
columns => ["code","color"]
}
mutate {
remove_field => ["path", "host"]
}
(...)
并且对于信息,如果字段path
和/或host
不存在,则没有问题。如果字段存在,插件将删除字段,如果字段不存在,则不执行任何操作。
编辑:我已经对它进行了新鲜测试elastic stack
:
您可以使用以下方法删除索引:
curl -X DELETE "localhost:9200/emp5"
另请注意,在您当前的配置中logstash
只会读取一次文件。sincedb_path => "/dev/null"
您可以通过添加or in Windows
case:来更改该行为sincedb_path => "NUL"
:
input {
file {
(...) # here
}
部分。
然后在logstash
工作后验证结果:
curl -X GET "localhost:9200/emp5?pretty"
{
"emp5" : {
"aliases" : { },
"mappings" : {
"doc" : {
"properties" : {
"@timestamp" : {
"type" : "date"
},
"@version" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"code" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"color" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"message" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
},
"settings" : {
"index" : {
"number_of_shards" : "5",
"blocks" : {
"read_only_allow_delete" : "true"
},
"provided_name" : "emp5",
"creation_date" : "1576099826712",
"number_of_replicas" : "1",
"uuid" : "reXYzqPgQryYcASoov9l5A",
"version" : {
"created" : "6080599"
}
}
}
}
}
如您所见,没有host
andpath
字段。
推荐阅读
- c# - 如何在 WPF 中使用 IValidatableObject 显示错误消息?
- regex - 重定向到具有部分已知/部分未知文件名的 CSS/JS 文件
- selenium - restartBrowserBetweenTests 与 onPrepare() 之间的交互
- rest - 测试时出错:为测试类找到了多个@BootstrapWith 声明
- c# - 使用 SoapPortClient 时如何设置代理?
- javascript - 将功能导入插件 JS 文件?
- java - 使用 Java Rally Rest API 提取 Rally 缺陷讨论
- sql-server - 从 SQL Developer 连接 SQL Server
- c++ - C++ 创建新的运算符并重载当前的运算符
- grafana - Grafana 以指定时间为单位进行测量