如何使用 Logstash 将数据上传到现有索引?
How to upload data to an existing index with Logstash?
我正在尝试使用 Logstash 将数据从 .csv 文件插入到现有索引(已经有数据)。
无论如何这是我的 logstash_true.config 文件:
input {
file {
path => "pathToFile"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
csv {
separator => ","
columns => ["title", "text", "subject", "date"]
}
}
output {
stdout { codec => rubydebug }
elasticsearch {
hosts => "127.0.0.1:9200"
index => "news"
document_type => "true_news"
document_id => "%{id}"
}
}
上传数据时,在命令行中看到文件或数据没有任何问题,document_type true_news真实存在
但是在尝试获取数据时:
{
"count" : 0,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
}
}
数据未加载。
更新
启用调试时出现以下错误:
Could not index event to Elasticsearch. {:status=>400, :action=>
["index", {:_id=>"%{id}", :_index=>"news", :routing=>nil,
:_type=>"true_news"}, #<LogStash::Event:0x7e10d60f>], :response=>
{"index"=>{"_index"=>"news", "_type"=>"true_news", "_id"=>"%{id}",
"status"=>400, "error"=>{"type"=>"illegal_argument_exception",
"reason"=>"Rejecting mapping update to [news] as the final mapping
would have more than 1 type: [fake_news, true_news]"}}}}
从 Elasticsearch 版本 6.0 开始,您的索引中不能有多种类型。
您的索引 news
似乎已经有类型为 fake_news
的文档或映射,而您正试图插入类型为 true_news
的文档,这是不可能的,那是为什么会出现此错误:
"type"=>"illegal_argument_exception",
"reason"=>"Rejecting mapping update to [news] as the final mapping
would have more than 1 type: [fake_news, true_news]"
由于您只能有一种类型,并且您希望能够区分 true_news
和 fake_news
,因此最好重新创建索引以使用默认类型,doc
, 对于每个文档,并使用输入中的配置 add_tag => ["tag"]
添加带有 true_news
或 fake_news
的标签。
我正在尝试使用 Logstash 将数据从 .csv 文件插入到现有索引(已经有数据)。
无论如何这是我的 logstash_true.config 文件:
input {
file {
path => "pathToFile"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter {
csv {
separator => ","
columns => ["title", "text", "subject", "date"]
}
}
output {
stdout { codec => rubydebug }
elasticsearch {
hosts => "127.0.0.1:9200"
index => "news"
document_type => "true_news"
document_id => "%{id}"
}
}
上传数据时,在命令行中看到文件或数据没有任何问题,document_type true_news真实存在
但是在尝试获取数据时:
{
"count" : 0,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
}
}
数据未加载。
更新
启用调试时出现以下错误:
Could not index event to Elasticsearch. {:status=>400, :action=>
["index", {:_id=>"%{id}", :_index=>"news", :routing=>nil,
:_type=>"true_news"}, #<LogStash::Event:0x7e10d60f>], :response=>
{"index"=>{"_index"=>"news", "_type"=>"true_news", "_id"=>"%{id}",
"status"=>400, "error"=>{"type"=>"illegal_argument_exception",
"reason"=>"Rejecting mapping update to [news] as the final mapping
would have more than 1 type: [fake_news, true_news]"}}}}
从 Elasticsearch 版本 6.0 开始,您的索引中不能有多种类型。
您的索引 news
似乎已经有类型为 fake_news
的文档或映射,而您正试图插入类型为 true_news
的文档,这是不可能的,那是为什么会出现此错误:
"type"=>"illegal_argument_exception",
"reason"=>"Rejecting mapping update to [news] as the final mapping
would have more than 1 type: [fake_news, true_news]"
由于您只能有一种类型,并且您希望能够区分 true_news
和 fake_news
,因此最好重新创建索引以使用默认类型,doc
, 对于每个文档,并使用输入中的配置 add_tag => ["tag"]
添加带有 true_news
或 fake_news
的标签。