【问题标题】:How can I make indexing json file by using logstash?如何使用logstash制作索引json文件?
【发布时间】:2017-09-15 13:52:09
【问题描述】:

我尝试为我的 json 文件创建索引,如下所示。我必须写一个 grok 表达式。但我不能这样做吗?你能帮帮我吗?

{"level":"Information","ClientIP":"10.201.21.188","Test":"10.210.21.188"}
{"level":"Information","ClientIP":"10.202.21.187","Test":"10.220.21.188"}
{"level":"Information","ClientIP":"10.203.21.186","Test":"10.230.21.188"}
{"level":"Information","ClientIP":"10.204.21.185","Test":"10.240.21.188"}

我的 logstash.conf 如下:

input {
  file {
    type => "json"
    path => ["C:/logs/test-20170933.json"]
    start_position => "beginning"
  }
}
filter {
  grok { 
         match => [ "message","%{WORD:level}   I HAVE TO WRITE OTHER ELEMENTS  BUT HOW????"]
  }
  json {
          source => "message"
       }
}
output {
	 stdout {
    codec => rubydebug
    }
    elasticsearch {
        hosts => [ "localhost:9200" ]
        index => "logstash-%{+YYYY.MM.dd}"
    }
}

我想我们需要 grok 表达式来实现这一点。我也愿意为此提供新的创意解决方案。

【问题讨论】:

    标签: elasticsearch logstash elastic-stack logstash-grok logstash-configuration


    【解决方案1】:

    您不需要了解任何内容,您的 file 输入只需要一个 JSON 编解码器,您就可以开始了:

    input {
      file {
        type => "json"
        path => ["C:/logs/test-20170933.json"]
        start_position => "beginning"
        codec => "json"                  <-- add this
      }
    }
    filter {
    }
    output {
        stdout {
            codec => rubydebug
        }
        elasticsearch {
            hosts => [ "localhost:9200" ]
            index => "logstash-%{+YYYY.MM.dd}"
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-26
      • 1970-01-01
      • 2017-11-02
      • 2020-09-27
      • 2023-04-01
      • 2017-10-13
      相关资源
      最近更新 更多