Elasticsearch索引自动套用模板

摘要:
方案选择:方案1:可以如下配置logstash的输出参数:该方案指定logstash中的模板文件,logstash将模板写入ES集群;方案2:直接将模板写入ES集群,并通过ES提供的API将JSON格式模板写入目标ES集群。模板路径用于将模板直接应用于所有新生成的符合过滤规则的索引。

方案选择:

方案一:可对logstash配置output参数:

Elasticsearch索引自动套用模板第1张

 如下所示:

Elasticsearch索引自动套用模板第2张

 这种方案在logstash中指定模板文件,由logstash将template写入ES集群;

方案二:直接将template写入ES集群

通过ES提供的API,将JSON格式的template写入目标ES集群的_template路径,对新生成的所有符合过滤规则的索引直接套用该模板。

模板的结构大致分四块吧:

第一部分:通用设置,主要是模板匹配索引的过滤规则,影响该模板对哪些索引生效;

第二部分:settings:配置索引的公共参数,比如索引的replicas,以及分片数shards等参数;

第三部分:mappings:最重要的一部分,在这部分中配置每个type下的每个field的相关属性,比如field类型(string,long,date等等),是否分词,是否在内存中缓存等等属性都在这部分配置;

第四部分:aliases:索引别名,索引别名可用在索引数据迁移等用途上。

典型的一个template如下所示:

{
        "template": "ld.log-*",
        "order":0,
        "settings": {
            "index.number_of_replicas": "1",
            "index.number_of_shards": "5"
        },
        "mappings": {
            "logs": {
                "properties": {
                    "@timestamp": {
                        "type": "date",
                        "format": "strict_date_optional_time||epoch_millis"
                    },
                    "@version": {
                        "doc_values": true,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "Exp": {
                        "doc_values": true,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "Guid": {
                        "doc_values": true,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "LogLevel": {
                        "type": "long"
                    },
                    "LogTime": {
                        "type": "date",
                        "format": "strict_date_optional_time||epoch_millis"
                    },
                    "LoggerName": {
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "Message": {
                        "doc_values": true,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "ProcessId": {
                        "type": "long"
                    },
                    "StackTrace": {
                        "doc_values": true,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "ThreadId": {
                        "type": "long"
                    },
                    "exp": {
                        "doc_values": true,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "logLevel": {
                        "type": "long"
                    },
                    "logTime": {
                        "doc_values": true,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "loggerName": {
                        "doc_values": true,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "message": {
                        "doc_values": true,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "processId": {
                        "type": "long"
                    },
                    "tags": {
                        "doc_values": true,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "threadId": {
                        "type": "long"
                    }
                }
            }
        },
        "aliases": {
        }
}

在这个JSON中可以清楚地看到四个部分,并且对string类型的fields设置了不进行默认分词信息。

免责声明:文章转载自《Elasticsearch索引自动套用模板》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇修改配置文件application.propertiesvim 的列操作下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Delphi 匿名函数的几个实际应用(二)

Timing Anonymous Methods 计时功能匿名函数   开发者们经常需要添加计时代码到一个已有的常规过程中,比较他们的相关速度。前面例子已经使用了几次实例,指出Uncode字符执行速度。对比两个代码片段,比较他们的执行毫秒数,妳可以写出下面内容(在本书第二章的“转换字符”例子):   [delphi]view plaincopy...

mssql 数据库 基本知识

数据库中禁用/启用标识列的自增长 SET IDENTITY_INSERT [ database_name . [ schema_name ] . ] table { ON | OFF } 恢复数据时要让标识列可以插入数据,必须设置上面的属性为ON -----------------------------------------------...

ant Form 常用 api

经过 Form.create 包装的组件将会自带 this.props.form 属性,this.props.form 提供的 API 如下: 注意:使用 getFieldsValue getFieldValue setFieldsValue 等时,应确保对应的 field 已经用 getFieldDecorator 注册过了。 方法      说明...

Swift 自定义Useragent

Swift 自定义Useragent 背景 最近在接阿里云的WAF,防火墙会拦截某些请求。被拦截的请求是看不到Headers信息的,只能看到Useragent,所以,应后台需求,自定义Useragent,这样可以更方便从服务器日志定位问题。 准备 当前项目中使用的是Alamofire进行网络请求。 通过查看源码发现,默认的SessionManager是初始...

IDEA+SpringBoot整合Swagger2创建API文档

------------恢复内容开始------------ 1.创建SpringBoot项目 2.选择快捷方式创建springboot项目          3.工程文件树形图  4.pom.xml中导入Swagger依赖  代码如下: 1 <dependency> 2 <groupId&...

6、jeecg 笔记之 自定义excel 模板导出(一)

1、前言 jeecg 中已经自带 excel 的导出导出功能,其所使用的是 easypoi,尽管所导出的 excel 能满足大部分需求, 但总是有需要用到自定义 excel 导出模板,下文所用到的皆是 easypoi 提供的,为方便下次翻阅,故记之。 2、代码部分 2.1、controller @RequestMapping("/myExcel")...