使用Logstash创建ES映射模版并进行数据默认的动态映射规则
2024-10-18 23:24:17
本文配置为 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" }
}
}
}
}
}
}
这里关注几个属性index
、template_name
、以及模板文件中的 template
。index
是索引的名称,我们经常会有诸如 index => "logstash-%{+YYYY.MM.dd}”
这样的索引名称,可以按照日期来分割不同的索引。template_name
对应的是模板名称,template
这是比较关键的,因为决定了索引是否能够匹配到模板配置,这里应该与 index
相匹配。比如固定的 index 名称,这里就可以是固定名称。对于按日期分隔的,可以使用通配符,例如logstash-*
。
我就是因为没搞明白这几个属性的对应关系,导致自己的配置没有生效查了很长时间。
参考资料
1、Logstash中配置默认索引映射(_default_属性)
2、关于动态Mapping和templates
最新文章
- js生成带参的二维码
- Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
- 《HelloGitHub月刊》第05期
- 查找问题的利器 - Git Blame
- Linux建立软连接
- struts2下实现的json传递list,object。
- 安装apk文件报waiting for device 时解决办法
- multiselect2side双向选择列表插件改进版
- [tools] sublime 使用记录
- EF 已有打开的与此 Command 相关联的 DataReader,必须首先将它关闭
- Problem A
- HDU4355-Party All the Time-三分
- SqlServer2008_r2安装功能选择
- 使用mongo-express管理mongodb数据库
- MT【293】拐点处切线
- 利用Fiddler拦截接口请求并篡改数据
- IDEA的安装
- jdk安装环境变量配置
- 随机x到x之间的值
- IE8“开发人员工具”(上)
热门文章
- 如何用node.js批量给图片加水印
- CSS transform中的rotate的旋转中心怎么设置
- 004.iSCSI客户端配置示例-Linux
- auth.User.groups: (fields.E304)
- 使用ajax与jqplot的小体会
- 我的php.ini上传文件配置
- gson Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path
- Ajax之xmlhttp.open()的用法
- java集合之vector容器
- how convert large HEX string to binary array ?