本文配置为 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

最新文章

  1. js生成带参的二维码
  2. Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
  3. 《HelloGitHub月刊》第05期
  4. 查找问题的利器 - Git Blame
  5. Linux建立软连接
  6. struts2下实现的json传递list,object。
  7. 安装apk文件报waiting for device 时解决办法
  8. multiselect2side双向选择列表插件改进版
  9. [tools] sublime 使用记录
  10. EF 已有打开的与此 Command 相关联的 DataReader,必须首先将它关闭
  11. Problem A
  12. HDU4355-Party All the Time-三分
  13. SqlServer2008_r2安装功能选择
  14. 使用mongo-express管理mongodb数据库
  15. MT【293】拐点处切线
  16. 利用Fiddler拦截接口请求并篡改数据
  17. IDEA的安装
  18. jdk安装环境变量配置
  19. 随机x到x之间的值
  20. IE8“开发人员工具”(上)

热门文章

  1. 如何用node.js批量给图片加水印
  2. CSS transform中的rotate的旋转中心怎么设置
  3. 004.iSCSI客户端配置示例-Linux
  4. auth.User.groups: (fields.E304)
  5. 使用ajax与jqplot的小体会
  6. 我的php.ini上传文件配置
  7. gson Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path
  8. Ajax之xmlhttp.open()的用法
  9. java集合之vector容器
  10. how convert large HEX string to binary array ?