我在从另一个系统的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的所有元数据,并且无法将其插入新的推送中。有没有办法让我使用文件中的元数据,而不是新创建的元数据?

最佳答案

我认为您应该使用elasticdump将此转储文件提取到elasticsearch中,它将使用输入日志中存在的元数据创建索引,或者甚至可以显式指定索引的名称。

flex 转储的链接:->
https://www.npmjs.com/package/elasticdump
elasticdump非常易于使用,有时证明非常有用。

在上述情况下,我只需要使用以下命令(json_stack.log包含输入日志):->

elasticdump --input=json_stack.log --output=http://192.168.133.187:9200/

这将基于输入日志中存在的元数据创建索引:-^
elasticdump --input=json_stack.log --output=http://192.168.133.187:9200/bhavya

这将创建名称为bhavya的索引:-^

也可以使用logstash来摄取这些数据,但是更简单,更好的方法是使用elasticdump。如果您需要安装 flex 转储的帮助,我将告诉您步骤,但请先尝试自己安装它。

10-01 17:09
查看更多