logstash写数据到elasticsearch如何指定多个数据 template

之前在配置从logstash写数据到elasticsearch时,指定单个数据模板没有问题,但是在配置多个数据模板时候,总是不成功,后来找了很多资料,终于找到解决办法,就是要多加一个配置项: template_name ,切该名字必须全部为小写

  参考配置信息:

output {
        if [type] == "log_01" {
                elasticsearch {
                        cluster => 'elasticsearch'
                        host =>         'x.x.x.x'
                        index => 'log_01-%{+YYYY-MM-dd}'
                        port => '9300'
                        workers => 1
                        template => "/data/logstash/conf/template_01.json"
                        template_name => "template_01.json"
                        template_overwrite => true
                }
        }
        if [type] == "log_02" {
            elasticsearch {
                        cluster => 'elasticsearch'
                        host =>         'x.x.x.x'
                        index => 'log_02-%{+YYYY-MM-dd}'
                        port => '9300'
                        workers => 1
                        template => "/data/logstash/conf/template_02.json"
                        template_name => "template_01.json"
                      template_overwrite => true
                }
        }
}

模板的配置请参见:http://qindongliang.iteye.com/blog/2290384

没指定之前的写法:

修改后的文件格式:


temp.json参考格式:





{
"template": "index_ytx_inlife_item_category",
  "version": 50001,
  "settings": {
    "index.refresh_interval": "5s"
  },
  "mappings": {
    "_default_": {
      "_all": {
        "enabled": true,
        "norms": false
      },
      "dynamic_templates": [
        {
          "template_1" : {
            "match" : "name",
            "mapping" : {
              "type" : "string",
              "analyzer":"ik_smart",
              "fields": {
                "raw": { 
                  "type":  "string",
                  "index": "not_analyzed"
                }
              }
            }
          }
        },
        {
          "template_2" : {
            "match" : "*",
            "match_mapping_type" : "string",
            "mapping" : {
              "type" : "string",
              "index" : "not_analyzed"
            }
          }
        }
      ]
    }
  }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值