通过 logstash 配置读取和使用 elasticsearch metada
Reading and using elasticsearch metada with logstash configuration
我在从另一个系统中的 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."}}}}
我怀疑是因为转储文件已经包含了以前虚拟机中Elasticsearch的所有元数据,并且无法将其插入到新的推送中。有没有办法让我使用文件中的元数据而不是新创建的元数据?
我认为您应该使用 elasticdump
将此 es 转储文件提取到 elasticsearch
。它将使用输入日志中存在的元数据创建索引,或者您甚至可以指定索引的名称明确地。
Link 用于弹性转储:->
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
。如果您在安装 elasticdump 时需要帮助,我会告诉您步骤,但请尝试安装首先是你自己。
我在从另一个系统中的 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."}}}}
我怀疑是因为转储文件已经包含了以前虚拟机中Elasticsearch的所有元数据,并且无法将其插入到新的推送中。有没有办法让我使用文件中的元数据而不是新创建的元数据?
我认为您应该使用 elasticdump
将此 es 转储文件提取到 elasticsearch
。它将使用输入日志中存在的元数据创建索引,或者您甚至可以指定索引的名称明确地。
Link 用于弹性转储:-> 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
。如果您在安装 elasticdump 时需要帮助,我会告诉您步骤,但请尝试安装首先是你自己。