logstash 输出到elasticsearch 自动建立index

      由于es 单index 所能承受的数据量有限,之前情况是到400w数据300G左右的时候,整个数据的插入会变得特别慢(索引重建)甚至会导致集群之间的通信断开,于是我们采用每天一个index的方法来缓解压力,logstash 默认是支持每天产生索引的默认名为 logstash-yyyy.MM.dd 那么我们怎么才能重命名它呢,或者当我们有多个logstash实例的时候怎么才能让他们分别开来。

 

     其实logstash的es  output中  有几个参数是控制此选项的:

     

    index => "dylocation-%{+YYYY.MM.dd}" // 和模板中得template 名称 匹配  如果匹配ok 则采用此模板
    template_overwrite => true  //  覆盖当前模板的一个参数 覆盖 template 和 template_name  

    

   其实呢  index的名字是和logstash中output 中得elasticsearch中得 template 匹配的怎么个匹配法呢 我们看看 默认的一个模板

   /xxx/logstash/lib/logstash/outputs/elasticsearch  下的  elasticsearch-template.json

  

{
  "template" : "logstash-*",
  "settings" : {
    "index.refresh_interval" : "5s"
  },
  "mappings" : {
    "_default_" : {
       "_all" : {"enabled" : true},
       "dynamic_templates" : [ {
         "string_fields" : {
           "match" : "*",
           "match_mapping_type" : "string",
           "mapping" : {
             "type" : "string", "index" : "analyzed", "omit_norms" : true,
               "fields" : {
                 "raw" : {"type": "string", "index" : "not_analyzed", "ignore_above" : 256}
               }
           }
         }
       } ],
       "properties" : {
         "@version": { "type": "string", "index": "not_analyzed" },
         "geoip"  : {
           "type" : "object",
             "dynamic": true,
             "path": "full",
             "properties" : {
               "location" : { "type" : "geo_point" }
             }
         }
       }
    }
  }
}

   也就说

posted @ 2015-12-09 22:12  NPH  阅读(3451)  评论(3编辑  收藏  举报