用于 elasticsearch 的具有可变索引名称的 logstash 配置

logstash configuration with variable index name for elasticsearch

我有一个 logstash 配置,它从 redis 获取数据并将数据输出到 elasticsearch。这是我的配置文件的样子:

input {
    redis {
        host => "127.0.0.1"
        codec => "json"
        key => "logstash"
        data_type => "list"
    }
}

output {
    elasticsearch {
        protocol => "http"
        user => "user"
        password => "password"
        host => "host:9200"
        index => "index-%{foo}"
        document_id => "id-%{bar}"
        document_type => "my_type"
        cluster => "my_cluster"
    }
}

我的 elasticsearch 实例由 nginx 在端口 9200 上代理,实际上它 运行 在不同的端口上。另外 auth 是使用 nginx 设置的,而不是 shield。问题是,当我在此配置上 运行 a configtest 时,它显示 Configuration OK。但是当我 运行 这个脚本然后抛出这个错误:

Pipeline aborted due to error {:exception=>"LogStash::ConfigurationError", 
:backtrace=>["/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-
2.4.0-java/lib/logstash/config/mixin.rb:88:in `config_init'", 
"org/jruby/RubyHash.java:1342:in `each'", 
"/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-
java/lib/logstash/config/mixin.rb:72:in `config_init'", 
"/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-
java/lib/logstash/outputs/base.rb:79:in `initialize'", 
"/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-
java/lib/logstash/output_delegator.rb:74:in `register'", 
"/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-
java/lib/logstash/pipeline.rb:181:in `start_workers'", 
"org/jruby/RubyArray.java:1613:in `each'", 
"/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-
java/lib/logstash/pipeline.rb:181:in `start_workers'", 
"/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-
java/lib/logstash/pipeline.rb:136:in `run'", 
"/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-
java/lib/logstash/agent.rb:491:in `start_pipeline'"], :level=>:error}

为什么会抛出这个错误?我在这里做错了什么?

编辑

请注意,我也尝试过使用

host => "http://user:password@host:9200"

但这也不起作用。

如果您使用的是 Logstash 版本 2+,则不是 host,而是 hosts

比照documentation

hosts
Value type is array
Default value is ["127.0.0.1"]
Sets the host(s) of the remote instance.