【问题标题】:How do I increment my count field of my document from logstash?如何从 logstash 增加我的文档的计数字段?
【发布时间】:2015-08-25 07:22:14
【问题描述】:

我想从 logstash 更新我的文档/登录 elasticsearch 的一个字段。

我的 logstash 配置文件

input { 
    http {
    host => "127.0.0.1" # default: 0.0.0.0
    port => 31311 # default: 8080
  }
}

output { 
  stdout { codec => json },
  elasticsearch {
        action => "update"
        bind_host => "127.0.0.1"
        bind_port => 9200
        document_id => "ET00009682"
        index => "in12"
        type => "event"
  }
}

我想将我的计数字段增加一,如何在我的 logstash 输出中指定它。

注意:我知道更新我需要使用这个脚本

"script" : "ctx._source.count += 1"

但我不确定将其放置在 logstash 的输出中的什么位置?

请帮助 谢谢

【问题讨论】:

    标签: elasticsearch logstash elastic-stack


    【解决方案1】:

    你可以用 conf 做到这一点:

    output { 
      stdout { codec => json },
      elasticsearch {
            action => "update"
            bind_host => "127.0.0.1"
            bind_port => 9200
            document_id => "ET00009682"
            index => "in12"
            type => "event"
            doc_as_upsert => true
            script => "ctx._source.count += 1"
            script_lang => "groovy"
            script_type => "inline"
      }
    }
    

    【讨论】:

      【解决方案2】:

      您需要在有计数器的地方使用指标过滤器:https://www.elastic.co/guide/en/logstash/current/plugins-filters-metrics.html

      filter {
        metrics {
          meter => [ "thing" ]
          add_tag => "metric"
        }
      }
      

      您将收到一个字段名称:thing.count,这将是您的计数字段

      【讨论】:

        【解决方案3】:

        所以我所做的是从 logstash 的输出中触发 curl 请求来实现这一点。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-11-18
          • 1970-01-01
          • 2018-04-26
          • 2021-02-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多