Elasticsearch 索引模版(Index template)

目录

 

一、问题产生背景

二、作用

三、添加索引模版

四、更新索引模版

五、查询索引模版

六,删除索引模版


一、问题产生背景

在做Elasticsearch和Logstash集成时,由于ES默认的索引分片数是5、副本数是1,导致Logstash在ES中创建索引时,引起ES的健康值变黄。虽然目前看上去没有问题,但是黄颜色,始终不健康。因此,找寻是否有默认索引方案。由此搜索ES官方文档,发现可以添加索引模版(Index template)。

二、作用

当创建索引时,索引模版可以定义索引的设置和相关字段映射。ES会基于匹配索引名字的方式,将模板应用于创建新的索引。

模版索引,只会在索引创建过程中起作用,不会影响已经存在的索引。具体的settings和mapping的配置,可以参考创建索引的api。

如下为原文:

Index templates define settings and mappings that you can automatically apply when creating new indices. Elasticsearch applies templates to new indices based on an index pattern that matches the index name.

Index templates are only applied during index creation. Changes to index templates do not affect existing indices. Settings and mappings specified in create index API requests override any settings or mappings specified in an index template.

三、添加索引模版

请求形式 PUT

内容格式 application/json

请求地址 /_template/<index-template>

<index-template> 索引模版名称

请求body中参数

参数名称是否必传类型默认值说明
index_patternsarray of strings 在创建过程中,匹配索引名字的通配符
settingsindex setting object 索引设置,包括分片数和副本数量等,具体详见索引设置
orderinteger0该索引模版的权重值。
当有多个索引模版时,order值越小,越先匹配;order值越大,越后匹配
createbooleanFALSE标明该索引模版是否被替换或者更新
timeouttime unit30s请求响应时间
master_timeouttime unit30s连接主节点的请求响应时间
aliasesalias object 索引别名,详见更新索引别名设置
mappingsmapping object 索引映射
versioninteger 索引模版的版本号

调用举例

四、更新索引模版

和添加一致,只需要保证索引模版的名字一样就行。

五、查询索引模版

请求形式 GET

内容格式 application/json

请求地址 /_template/<index-template1>[,<index-template2>]

<index-template> 索引模版名称

如果要获取多个索引模版,用逗号隔开

如果不加索引模板名字,则是获取当前ES中所有的索引模版信息。

调用举例

六,删除索引模版

请求形式 DELETE

内容格式 application/json

请求地址 /_template/<index-template>

<index-template> 索引模版名称

调用举例

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值