一,模板简述:template大致分成setting和mappings两部分:
索引可使用预定义的模板进行创建,这个模板称作Index templates。模板设置包括settings和mappings,通过模式匹配的方式使得多个索引重用一个模板。 
1. settings主要作用于index的一些相关配置信息,如分片数、副本数,tranlog同步条件、refresh等。
 
2. mappings主要是一些说明信息,大致又分为_all、_source、prpperties这三部分:
 
     (1) _all:主要指的是AllField字段,我们可以将一个或多个都包含进来,在进行检索时无需指定字段的情况下检索多个字段。设置“_all" : {"enabled" : true}
 
     (2) _source:主要指的是SourceField字段,Source可以理解为ES除了将数据保存在索引文件中,另外还有一份源数据。_source字段在我们进行检索时相当重要,如果在{"enabled" : false}情况下默认检索只会返回ID, 你需要通过Fields字段去到索引中去取数据,效率不是很高。但是enabled设置为true时,索引会比较大,这时可以通过Compress进行压缩和inclueds、excludes来在字段级别上进行一些限制,自定义哪些字段允许存储。
 
     (3) properties:这是最重要的步骤,主要针对索引结构和字段级别上的一些设置。
3.咱们通常在elasticsearch中 post mapping信息,每重新创建索引便到设置mapping,分片,副本信息。非常繁琐。强烈建议大家通过设置template方式设置索引信息。设置索引名,通过正则匹配的方式匹配到相应的模板。ps:直接修改mapping的优先级>索引template。索引匹配了多个template,当属性等配置出现不一致的,以order的最大值为准,order默认值为0
二,创建模板:
例如:

{
"template": "pmall*",
"settings": {
"index.number_of_shards": 1,
"number_of_replicas": 4,
"similarity": {
"IgnoreTFSimilarity": {
"type": "IgoreTFSimilarity"
}
}
},
"mappings": {
"_default_": {
"_source": {
"enabled": false
}
},
"commodity": {
"properties": {
"sold": {
"type": "long"
},
"online_time": {
"type": "long"
},
"price": {
"type": "long"
},
"publish_time": {
"type": "long"
},
"id": {
"type": "long"
},
"catecode": {
"type": "integer"
},
"title": {
"search_analyzer": "ikSmart",
"similarity": "IgnoreTFSimilarity",
"analyzer": "ik",
"type": "text"
},
"content": {
"index": false,
"store": true,
"type": "keyword"
},
"status": {
"type": "integer"
}
}
}
}
}

三,删除模板:


DELETE /_template/template_1

四,查看模板:

GET /_template/template_1

也可以通过模糊匹配得到多个模板信息

GET /_template/temp* 

可以批量查看模板

GET /_template/template_1,template_2

验证模板是否存在:

HEAD _template/template_1

五:多个模板同时匹配,以order顺序倒排,order越大,优先级越高



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

六,模板版本号:
 
模板可以选择添加版本号,这可以是任何整数值,以便简化外部系统的模板管理。版本字段是完全可选的,它仅用于模板的外部管理。要取消设置版本,只需替换模板即可

创建模板:

PUT /_template/template_1
{
"template" : "*",
"order" : 0,
"settings" : {
"number_of_shards" : 1
},
"version": 123
}

查看模板版本号:

GET /_template/template_1?filter_path=*.version

响应如下:

{
"template_1" : {
"version" : 123
}
}

七,参考:
indices-templates

【基础篇】elasticsearch之索引模板Template[转]的更多相关文章

  1. Elasticsearch之索引模板index template与索引别名index alias

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

  2. WPF基础篇之控件模板(ControlTemplate)

    WPF中每一个控件都有一个默认的模板,该模板描述了控件的外观以及外观对外界刺激所做出的反应.我们可以自定义一个模板来替换掉控件的默认模板以便打造个性化的控件. 与Style不同,Style只能改变控件 ...

  3. Django 基础篇(二)视图与模板

    视图 在django中,视图对WEB请求进行回应 视图接收reqeust对象作为第一个参数,包含了请求的信息 视图就是一个Python函数,被定义在views.py中 #coding:utf- fro ...

  4. Template 基础篇-函数模板(待看

    Template 基础篇-函数模板 Template所代表的泛型编程是C++语言中的重要的组成部分,我将通过几篇blog对这半年以来的学习做一个系统的总结,本文是基础篇的第一部分. Template ...

  5. ES 10 - Elasticsearch的索引别名和索引模板

    目录 1 索引模板概述 1.1 什么是索引模板 1.2 索引模板中的内容 1.3 索引模板的用途 2 创建索引模板 3 查看索引模板 4 删除索引模板 5 模板的使用建议 5.1 一个index中不能 ...

  6. .net 开源模板引擎jntemplate 教程:基础篇之语法

    一.基本概念 上一篇我们简单的介绍了jntemplate并写了一个hello world(如果没有看过的,点击查看),本文将继续介绍jntemplate的模板语法. 我们在讲解语法前,首先要了解一下标 ...

  7. elasticsearch 5.x 系列之四(索引模板的使用,详细得不要不要的)

    1,首先看一下下面这个索引模板 curl -XPUT "master:9200/_template/template_1?pretty" -H 'Content-Type: app ...

  8. ElasticStack学习(八):ElasticSearch索引模板与聚合分析初探

    一.Index Template与Dynamic Template的概念 1.Index Template:它是用来根据提前设定的Mappings和Settings,并按照一定的规则,自动匹配到新创建 ...

  9. ElasticSearch(六):索引模板

    ElasticSearch(六):索引模板 学习课程链接<Elasticsearch核心技术与实战> Index Template Index Template - 帮助你设定Mappin ...

随机推荐

  1. 进程篇:wait & waitpid

    #include <sys/types.h> /* 提供类型pid_t的定义 */ #include <sys/wait.h> pid_t wait(int *status) ...

  2. 2018-6-8随笔-combox绑定-语音-删空格

    1.下面介绍三种对comboBox绑定的方式,分别是泛型中IList和Dictionary,还有数据集DataTable ----->>>>>飞机票 2. 简单的语音播报 ...

  3. MySql基础笔记(二)Mysql语句优化---索引

    Mysql语句优化--索引 一.开始优化前的准备 一)explain语句 当MySql要执行一个查询语句的时候,它首先会对语句进行语法检查,然后生成一个QEP(Query Execution Plan ...

  4. 【PYTHON】 Missing parentheses in call to 'print'

    Microsoft Windows [版本 10.0.15063] (c) 2017 Microsoft Corporation.保留所有权利. C:\Users\Jam>python Pyth ...

  5. [SP10628]Count on a tree

    Description: 给定一颗n个点的树,有m个询问,求任意两点路径上点权第k小的点 Hint: \(n,m<=1e5\) Solution: 比较水 以每个点到根节点的数的前缀和建主席树 ...

  6. c++中static变量有什么用

    主要有两点用途. 1.让一个变量长期有效,而不管其是在什么地方被申明.比如: int fun1() { static int s_value = 0; .... } 那么fun1不管在什么地方被调用, ...

  7. Ubuntu安装软件时提示依赖项配置错误

    在终端中使用dpkg安装软件时有时会出现依赖项配置错误的情况, 解决方法是使用指令 sudo apt-get install -f 安装Ubuntu 16.04新系统不再配有的缺失依赖项,之后再次输入 ...

  8. H5微信单页读书日活动

    1. 页面方面 (1)单页面应用,使用jquery 绑定click事件来控制页面更换显示 (2)ajax请求获取图片数据,和海报名人名言数据 2.微信分享 (1)配置签名,后台导入微信第三方库配置签名 ...

  9. Mac上tesseract-OCR的安装配置

    Mac上tesseract-OCR的安装配置 tesseract简介 OCR(Optical Character Recognition)即光学字符识别技术,专门用于对图片文字进行识别,并获取文本. ...

  10. ionic2 隐藏滚动条

    方法 在全局样式,即app.scss里添加样式: ::-webkit-scrollbar { display: none !important; }