1、Index Templates

之前我们聊过Dynamic template,它作用范围是特定的Index,如果我们想针对全局Index进行设置该如何操作呢?

Index Templates 可以定义一些模板,新创建index的时候会自动应用相应的模板。

Index templates allow you to define templates that will automatically be applied when new indices are created.

PUT _template/template_1
{
"index_patterns": ["te*", "bar*"],
"settings": {
"number_of_shards": 1
},
"mappings": {
"type1": {
"_source": {
"enabled": false
},
"properties": {
"host_name": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z YYYY"
}
}
}
}
}

1)模板匹配规则

"index_patterns": ["te*", "bar*"],以te、bar开头的index都会应用到这个模板。

2)settings

index的一些属性设置,例如:分片数量。

3)mappings

field mapping,可以结合Dynamic template进行设置。

2、匹配到多个模板如何处理?

如果index匹配上了多个模板,那么这些模板的settings和mappings会被合并在一起。如果出现相同的配置项,会根据order的顺序进行覆盖(order大的覆盖小的)。

例如:

PUT /_template/template_1
{
"index_patterns" : ["*"],
"order" : 0,
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"type1" : {
"_source" : { "enabled" : false }
}
}
} PUT /_template/template_2
{
"index_patterns" : ["te*"],
"order" : 1,
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"type1" : {
"_source" : { "enabled" : true }
}
}
}

在上面的例子中,定义了两个template。template_1中order=0,_source enabled=false;template_2中order=1,_source enabled=true。

如果新创建的index名字不以te开头,则匹配上template_1,_source enabled=false。

如果新创建的index名字以te开头,则同时匹配上template_1、template_2,由于template_2中order大,因此_source enabled=true。

参考:

Index Templates

ES - Index Templates 全局index模板的更多相关文章

  1. Spark2.2+ES6.4.2(三十二):ES API之index的create/update/delete/open/close(创建index时设置setting,并创建index后根据avro模板动态设置index的mapping)

    要想通过ES API对es的操作,必须获取到TransportClient对象,让后根据TransportClient获取到IndicesAdminClient对象后,方可以根据IndicesAdmi ...

  2. elasticsearch index 之 create index(二)

    创建索引需要创建索引并且更新集群index matedata,这一过程在MetaDataCreateIndexService的createIndex方法中完成.这里会提交一个高优先级,AckedClu ...

  3. JQ first-child与:first的区别以及nth-child(index)与eq(index)的区别

    1.first-child和:first区别 first-child  是指选取每个父元素的第一个子元素 如$("div:first-child")指每个父级里的第一个div孩子 ...

  4. Index Seek和Index Scan的区别

    Index Seek是Sql Server执行查询语句时利用建立的索引进行查找,索引是B树结构,Sql Server先查找索引树的根节点,一级一级向下查找,在查找到相应叶子节点后,取出叶子节点的数据. ...

  5. Neo4j 两种索引Legacy Index与Schema Index区别

    Legacy Indexes 在Neo4j 2.0版本之前,Legacy index被称作indexes.这个索引是通过外部图存储在外的Lucene实现,允许“节点”和“联系”以key:value键值 ...

  6. PostgreSQL index types and index bloating

    warehouse_db=# create table item (item_id integer not null,item_name text,item_price numeric,item_da ...

  7. index full scan/index fast full scan/index range scan

    **************************1************************************* 索引状态:          valid.      N/A .    ...

  8. 14.4.3 Adaptive Hash Index 自适应hash index

    14.4.3 Adaptive Hash Index 自适应hash index 自适应hash index(AHI) 让InnoDB 执行更像内存数据库在系统使用合适的负载组合和足够的内存用于Buf ...

  9. index seek与index scan

    原文地址:http://blog.csdn.net/pumaadamsjack/article/details/6597357 低效Index Scan(索引扫描):就全扫描索引(包括根页,中间页和叶 ...

随机推荐

  1. [c++]大数运算---利用C++ string实现任意长度正小数、整数之间的加减法

    本文为大大维原创,最早于博客园发表,转载请注明出处!!! 一.概述 C/C++中的int类型能表示的范围是-2E31-2E31–1.unsigned类型能表示的范围是0-2E32–1,即 0-4294 ...

  2. shell、redis使用

    一.跳板机 来源:什么是跳板机 SSH[Secure Shell](远程连接工具)连接原理:ssh服务是一个守护进程(demon),系统后台监听客户端的连接,ssh服务端的进程名为sshd,负责实时监 ...

  3. Python基础学习总结(持续更新)

    https://www.cnblogs.com/jin-xin/articles/7459977.html 嗯,学完一天,白天上班,眼睛要瞎了= = DAY1 1,计算机基础. CPU:相当于人的大脑 ...

  4. Altium Designer 10 快捷键笔记

    一.放置.走线类: 1.交互式走线(Track):P T 2.铺铜(Fill):P F 3.大面积铺铜(Polygon):P G 4.自动扇出:元件封装上右键,C F 二.编辑类 1.调整铺铜(Pol ...

  5. 利用Python进行数据处理1——学会使用NumPy

    一.学会使用ndarray 1.1什么是ndarray? ndarray是NumPy中的一种多维数组对象,他可以是一维的.二维的.甚至更多维次.当然创建更多维次的数组并不是他的优点所在,他的优点在于它 ...

  6. excel 格式化姓名

                在做excel时,难免会遇到输入姓名对齐这种情况,如果数据少时我们可以手动敲空格来进行对齐,但数据量大时,手动调整就不是好办法了.     此时我们可以通过excel自带公式对 ...

  7. [ 随手记6 ] C/C++ 形参、实参、按值传参、指针传参、引用传参

    个人原创: 1. 形参:形式上的参数,一般多在函数声明.函数定义的参数上: 2. 实参:实体参数,有实际的值,在运算上被循环使用的值: 3. 按值传参:按值,就是把实际的值传给函数内部: 4. 指针传 ...

  8. 利用iftop找出是谁占用了带宽

    第一步:安装EPEL源    yum install epel-release 第二部:安装iftop         yum install iftop 然后用iftop命令即可查看相关信息 ift ...

  9. s21day13 python笔记

    s21day13 python笔记 一.装饰器 目的:在不改变原函数内部代码的基础上,在函数执行之前和之后自动执行某个功能 应用场景:想要为函数扩展功能时,可以选择用装饰器 装饰器基本格式: def ...

  10. SSH(Spring+Struts2+Hibernate) of mappings(SSH三大框架的映射问题)

    错误提示: org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity org.hibernate.Mapp ...