Logstash - 将日志文件的输出发送到elk

时间:2016-12-19 05:07:09

标签: elasticsearch logstash

我在弹性搜索中有一个索引,它有一个名为locationCoordinates的字段。它从logstash发送到ElasticSearch。

此字段中的数据如下所示......

-38.122, 145.025

当此字段出现在ElasticSearch中时,它不会成为地理位置。

我知道如果我在下面这样做,它就可以了。

{
  "mappings": {
    "logs": {
      "properties": {
        "http_request.locationCoordinates": {
          "type": "geo_point"
        }
      }
    }
  }
}

但我想知道的是如何更改我的logstash.conf文件以便它在启动时执行此操作。

目前我的logstash.conf看起来有点像......

input {

    # Default GELF input
    gelf {
        port => 12201
        type => gelf
    }

    # Default TCP input
    tcp {
        port => 5000
        type => syslog
    }

    # Default UDP input
    udp {
        port => 5001
        type => prod
        codec => json
    }
    file {
       path =>  [ "/tmp/app-logs/*.log" ]
       codec =>   json {
          charset => "UTF-8"
       }
       start_position => "beginning"
       sincedb_path => "/dev/null"
   }
}

filter {
   json{
      source => "message"
   }
}

output {
    elasticsearch {
        hosts => "elasticsearch:9200"
    }
}

我最终在Kibana中得到了这个(没有小地理标志)。

enter image description here

1 个答案:

答案 0 :(得分:0)

您只需修改elasticsearch输出即可配置索引模板,您可以在其中添加其他映射。

output {
    elasticsearch {
        hosts => "elasticsearch:9200"
        template_overwrite => true
        template => "/path/to/template.json"
    }
}

然后在/path/to/template.json的文件中,您可以添加额外的geo_point映射

{
  "template": "logstash-*",
  "mappings": {
    "logs": {
      "properties": {
        "http_request.locationCoordinates": {
          "type": "geo_point"
        }
      }
    }
  }
}

如果您想保留正式的logstash模板,可以download it并将特定的geo_point映射添加到其中。