zoukankan      html  css  js  c++  java
  • 使用Logstash创建ES映射模版并进行数据默认的动态映射规则

    本文配置为 ELK 即(Elasticsearch、Logstash、Kibana)5.5.1。

    Elasticsearch 能够自动检测字段的类型并进行映射,例如引号内的字段映射为 String,不带引号的映射为数字,日期格式的映射为日期等等,这个机制方便了我们快速上手 ELK,但是后期我们经常需要对一些特定的字段进行定制,之前本人有一篇文章进行这方面的尝试Logstash中如何处理到ElasticSearch的数据映射,但对于默认映射规则没有介绍,本文就来探讨一些默认的动态映射规则。

    开始之前

    先拿一个 logstash 的配置文件来看一下

    output {
      elasticsearch {
        hosts => “localhost:9200"
        index => "my_index"
        template => "/data1/cloud/logstash-5.5.1/filebeat-template.json"
        template_name => "my_index"
        template_overwrite => true
      }
      stdout { codec => rubydebug }
    }
    

    再看一个ES模板配置文件

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

    这里关注几个属性indextemplate_name、以及模板文件中的 templateindex是索引的名称,我们经常会有诸如 index => "logstash-%{+YYYY.MM.dd}”这样的索引名称,可以按照日期来分割不同的索引。template_name对应的是模板名称,template这是比较关键的,因为决定了索引是否能够匹配到模板配置,这里应该与 index相匹配。比如固定的 index 名称,这里就可以是固定名称。对于按日期分隔的,可以使用通配符,例如logstash-*

    我就是因为没搞明白这几个属性的对应关系,导致自己的配置没有生效查了很长时间。

    欢迎关注我的微信公众号

    参考资料
    1、Logstash中配置默认索引映射(_default_属性)
    2、关于动态Mapping和templates

  • 相关阅读:
    pytest 框架生成 pytest
    pytest 之数据驱动参数化:pytest.mark.parametrize
    web 网站表单测试、搜索查询测试、删除测试、数据库测试知识点
    pytest 之 fixture 的前置后置功能
    pytest 框架之pytest-html报告生成
    Initialization of bean failed; nested exception is java.lang.
    使用jmeter测试Oracle&&MySQL数据库性能
    jmeter的日常特殊参数化
    压测出现各种奇葩问题,求围观
    weblogic性能调优
  • 原文地址:https://www.cnblogs.com/cocowool/p/elk_dynamic_templates.html
Copyright © 2011-2022 走看看