HTML索引文件模板,索引模板(Index templates)

为什么需要索引模板?

在实际工作中,针对一批大量数据存储的时候需要使用多个索引库,如果手工指定每个索引库的配置信息(settings和mappings)的话就很麻烦了。所以,这个时候,就存在创建索引模板的必要了。

索引可以使用预定义的模板进行创建,这个模板称作Index templates。

模板设置包括settings和mappings,通过模式匹配的方式使得多个索引重用一个模板。

1. settings主要作用于index的一些相关配置信息,如分片数、副本数,tranlog同步条件、refresh等。

2. mappings主要是一些说明信息,大致又分为_all、_source、prpperties这三部分:

获取模板

GET _template/feature_template

GET _template/feature*

GET _template/template1,template2

验证模板是否存在

HEAD _template/template1

创建/更新模板

PUT _template/feature_template

{

"index_patterns": "feature*",

"settings": {

"number_of_replicas": 0,

"refresh_interval": "30s"

}

}

删除模板

DELETE _template/feature_template

创建多个索引模板

当存在多个索引模板,且某个索引两者都匹配时,settings和mappings将合成一个配置应用在这个索引上。合并的顺序可由索引模板的order属性来控制。

PUT _template/feature_template

{

"index_patterns": "feature*",

"order": 0,

"settings": {

"number_of_replicas": 0,

"refresh_interval": "30s"

}

}

注意:order值大的模板内容会覆盖order值小的。

模板配置文件

除了以上方式,索引模板也可以在文件中进行配置。索引模板的配置文件需要在每个主节点的config目录下,目录结构为:config/templates/template_1.json。

template_1.json的样例如下:

{

"template-logstash" : {

"template" : "logstash*",

"settings" : {

"index.number_of_shards" : 5,

"number_of_replicas" : 1,

"index" : {

"store" : {

"compress" : {

"stored" : true,

"tv": true

}

}

}

},

"mappings" : {

"_default_" : {

"properties" : {

"dynamic" : "true",

},

},

"loadbalancer" : {

"_source" : {

"compress" : true,

},

"_all" : {

"enabled" : false

},

"properties" : {

"@fields" : {

"dynamic" : "true",

"properties" : {

"client" : {

"type" : "string",

"index" : "not_analyzed"

},

"url" : {

"type" : "string",

"index" : "not_analyzed"

}

}

},

"@source" : {

"type" : "string",

"index" : "not_analyzed"

},

"@timestamp" : {

"type" : "date",

"format" : "dateOptionalTime"

},

"@type" : {

"type" : "string",

"index" : "not_analyzed",

"store" : "no"

}

}

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值