【问题标题】:Reading and using elasticsearch metada with logstash configuration通过 logstash 配置读取和使用 elasticsearch 元数据
【发布时间】: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


【解决方案1】:

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

弹性转储链接:-> 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 时需要帮助,我会告诉您步骤,但请先尝试自己安装。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-20
    • 1970-01-01
    • 2019-10-31
    • 2019-05-25
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多