【发布时间】:2018-07-11 23:28:24
【问题描述】:
我在另一个系统中从 elasticsearch 读取转储文件并使用 Logstash 通过文件输入插件将其推送到我的 elasticsearch 时遇到问题。我的转储文件如下所示:
{"_index":"logstash-2018.06.14","_type":"doc","_id":"9Q-9AGQBaaf188t_6DmH","_score":1,"_source":{"offset":124076,"tags":["filebeat_json","beats_input_raw_event","_jsonparsefailure"],...}
{"_index":"logstash-2018.06.14","_type":"doc","_id":"DQ-9AGQBaaf188t_6DqH","_score":1,"_source":{"offset":145573,"tags":["filebeat_json","beats_input_raw_event","_jsonparsefailure"],...}
我的配置文件如下:
input{
file{
path=> "/home/vm01/Documents/log/output.json"
type=>"log"
start_position => "beginning"
sincedb_path=>"/home/vm01/Documents/sincedb_redefined"
codec => multiline
{
pattern => '^\{'
negate => true
what => previous
}
}
}
filter{
if [type] == "log"{
json{
source=>"message"
}
}
}
output{
if [type] == "log"{
elasticsearch{
hosts=>"localhost:9200"
index=>"log-%{+YYYY.MM.dd}"
}
}
}
但它给了我这样的错误:
[WARN ] 2018-07-10 13:13:53.685 [Ruby-0-Thread-18@[main]>worker7: /usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:385] elasticsearch - Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"logstash-2018.07.10", :_type=>"doc", :_routing=>nil}, #<LogStash::Event:0x17052ccb>], :response=>{"index"=>{"_index"=>"logstash-2018.07.10", "_type"=>"doc", "_id"=>"gvflg2QB1n75DXFZzVPL", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"Field [_type] is a metadata field and cannot be added inside a document. Use the index API request parameters."}}}}
我怀疑这是因为转储文件已经包含来自以前 VM 的 Elasticsearch 的所有元数据,并且无法插入到新推送中。有没有办法让我使用文件中的元数据而不是新创建的元数据?
【问题讨论】:
-
为什么不使用re-index api或者snapshot和restore呢?除非重命名,否则不能在源中使用元数据字段。
标签: elasticsearch logstash logstash-configuration