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. 解决Exception in thread "main" java.nio.BufferOverflowException报错

    学习bytebuffer时,写了简单的demo报错: 错误的提示:Exception in thread "main" java.nio.BufferOverflowExcepti ...

  2. 转自:阮一峰 Git远程操作详解

      对于git的一些指令还是有些生疏,而且在课堂上讲的只是简单介绍了一些功能,并没有具体深入,看到这篇文章之后,觉得比较详细,所以转了过来. Git是目前最流行的版本管理系统,学会Git几乎成了开发者 ...

  3. js中的正则

    闭包: 函数在调用的时候会形成私有的作用域,对内部的变量起到保护的作用,这就是闭包: 变量销毁: 1.人为销毁 : var a = 12:   a = null: 2.孜然销毁 : 函数在调用完之后, ...

  4. 微信小程序实际开发中学习

    三个概念 微信:就是一个聊天工具 微信公众号:企业或个人用于管理其粉丝/用户的应用(类似于APP) 微信小程序:不需要下载安装直接可以使用的软件/应用/APP 小程序与公众号的区别: 定位不同(小程序 ...

  5. 深入理解java虚拟机《一》

    一.java发展史 1995.5.23 Oak语言改名为java,sun正式发布java 1.0版本 1996.1.23 JDK 1.0发布,java语言第一个正式版本运行环境 主要包括:java虚拟 ...

  6. Qt设置创建部分半透明,上面控件不透明

    //头文件#pragma once #include <QWidget> #include "ui_widgetFullAD.h" class widgetFullAD ...

  7. java.io.IOException: 你的主机中的软件中止了一个已建立的连接。

    1.异常表现:我在jsp文件中有一个<form>表单,里面有一个<button>保存事件按钮.<button  onclick="addOrUPdate()&q ...

  8. JavaScript·DOM,BOM

    YI.DOM 1.创建DOM 2.删除DOM 3.文档碎片 文档碎片可以提高DOM操作性能(理论上) 文档碎片(类似于一个口袋,先将多个元素放在口袋里,放完之后,再将口袋放到最终要插入的元素中): d ...

  9. SharePoint 2013 新特性 (三) 破改式 —— 设计管理器的使用 [1.设备通道]

    首先,哥们儿们会问,为啥要有设计管理器呢,不是原来就可以编辑页面了么,原来那个编辑不了模板页和布局页,也不能打包,而且也看不到具体HTML代码,不能编辑CSS,当然,你安装的SharePoint De ...

  10. python-文件锁

    文件锁(fcntl) fcntl这个模块是Python自带的,但Windows没有,可以手工下载fcntl.py文件,然后保存到python的Lib目录下 锁类型(fcntl.flock函数的第二个参 ...