【问题标题】:Logstash issues in creating index remove .raw field in kibana在 kibana 中创建索引删除 .raw 字段时出现 Logstash 问题
【发布时间】:2016-10-05 19:56:10
【问题描述】:

我已经编写了一个用于读取日志的 logstash conf 文件。如果我使用默认索引,即 logstash-*,我可以在 kibana 中看到 .raw 字段。但是,如果我在 logstash 中的 conf 文件中创建一个新索引,例如

output{
    elasticsearch {
      hosts => "localhost"
      index => "batchjob-*"} 
}

然后新索引不能配置.raw字段。有什么解决方法可以解决吗?非常感谢。

【问题讨论】:

    标签: elasticsearch logstash kibana


    【解决方案1】:

    原始字段由 Logstash elasticsearch 输出在 Elasticsearch 中创建的 specific index template 创建。

    您只需将该模板复制到名为batchjob.json 的文件中,然后将模板名称更改为batchjob-*(见下文)

    {
      "template" : "batchjob-*",
      "settings" : {
        "index.refresh_interval" : "5s"
      },
      "mappings" : {
        "_default_" : {
          "_all" : {"enabled" : true, "omit_norms" : true},
          "dynamic_templates" : [ {
            "message_field" : {
              "match" : "message",
              "match_mapping_type" : "string",
              "mapping" : {
                "type" : "string", "index" : "analyzed", "omit_norms" : true,
                "fielddata" : { "format" : "disabled" }
              }
            }
          }, {
            "string_fields" : {
              "match" : "*",
              "match_mapping_type" : "string",
              "mapping" : {
                "type" : "string", "index" : "analyzed", "omit_norms" : true,
                "fielddata" : { "format" : "disabled" },
                "fields" : {
                  "raw" : {"type": "string", "index" : "not_analyzed", "ignore_above" : 256}
                }
              }
            }
          } ],
          "properties" : {
            "@timestamp": { "type": "date" },
            "@version": { "type": "string", "index": "not_analyzed" },
            "geoip"  : {
              "dynamic": true,
              "properties" : {
                "ip": { "type": "ip" },
                "location" : { "type" : "geo_point" },
                "latitude" : { "type" : "float" },
                "longitude" : { "type" : "float" }
              }
            }
          }
        }
      }
    }
    

    然后你可以像这样修改你的elasticsearch 输出:

    output {
        elasticsearch {
          hosts => "localhost"
          index => "batchjob-*"
          template_name => "batchjob"
          template => "/path/to/batchjob.json"
        } 
    }
    

    【讨论】:

    • 这完美运行默认模板可以在/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-elasticsearch-2.7.1-java/lib/logstash/outputs/elasticsearch/elasticsearch-template.json 或尝试find /opt/logstash/ -type f -name "*template.json" 可能也取决于您使用的版本,链接似乎已关闭default template
    猜你喜欢
    • 1970-01-01
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 2018-07-28
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    • 2017-01-16
    相关资源
    最近更新 更多