带你读《Elastic Stack 实战手册》之23:——3.4.2.8.Index template(7)

简介: 带你读《Elastic Stack 实战手册》之23:——3.4.2.8.Index template(7)

《Elastic Stack 实战手册》——三、产品能力——3.4.入门篇——3.4.2.Elasticsearch基础应用——3.4.2.8.Index template(6) https://developer.aliyun.com/article/1230795


本例我们创建了名为bar-test-old的索引,其索引名以bar开头,匹配索引模板old_template的筛选规则,我们在创建时仅指定了副本数和 1 个ip属性,而使用 GET 请求查看索引信息时可以看出,索引模板中的别名配置、host_name属性和分片数的配置被使用了。但是关于_source的设置,由于创建索引时明确指出了,所以模板中的false配置被覆盖为了true

 

当匹配到多个老版索引模板时,最终配置为多个模板的组合,当不同模板配置了相同字段时,那么以order高的模板配置为准。示例如下:

 

# 创建新版索引模板   
PUT /_index_template/new_template   #1
{
   "index_patterns": ["template*"],
   "priority" : 100, 
   "template": {
    "mappings": {
      "dynamic": "true"
    },
    "aliases": {
      "new-template": {}
    }
  }
}
# 创建老版索引模板,不配置 order
PUT /_template/old_template_1     #2
{
  "index_patterns": ["temp*"],
   "mappings": {
      "dynamic": "false"
    },
  "aliases": {
      "old_template_1": {}
    }
}
# 创建老版本索引模板,配置高 order
PUT /_template/old_template_2?order=10  #3
{
  "index_patterns": ["temp-*"],
   "mappings": {
      "dynamic": "strict"
    },
  "aliases": {
      "old_template_2": {}
    }
}
# 创建索引,名称会匹配 new_template 模板和 old_template_1 模板
PUT /template-test    #4
{
  "settings": {
    "number_of_shards": 2
  },
  "mappings": {
    "properties": {
      "ip":{
        "type": "ip"
      }
    }
  }
}
# 查看索引配置
GET  /template-test  #5
# 返回
{
  "template-test" : {
    "aliases" : {
      "new-template" : { }  #  仅有新版本模板的别名设置
    },
    "mappings" : {
      "dynamic" : "true",
      "properties" : {
        "ip" : {
          "type" : "ip"
        }
      }
    },
    "settings" : {
      "index" : {
        "routing" : {
          "allocation" : {
            "include" : {
              "_tier_preference" : "data_content"
            }
          }
        },
        "number_of_shards" : "2",
        "provided_name" : "template-test",
        "creation_date" : "1620617781794",
        "number_of_replicas" : "1",
        "uuid" : "0PKYANozRya9zG3LdMG1UA",
        "version" : {
          "created" : "7100099"
        }
      }
    }
  }
}
# 创建索引,名称会匹配 old_template_1 模板和 old_template_1 模板
PUT /temp-test #6
{
  "settings": {
    "number_of_shards": 2
  },
  "mappings": {
    "properties": {
      "ip":{
        "type": "ip"
      }
    }
  }
}
# 查看索引配置
GET /temp-test
# 返回
{
  "temp-test" : {
    "aliases" : {
      "old_template_1" : { },  # old_template_1 的配置
      "old_template_2" : { }    # old_template_2 的配置
    },
    "mappings" : {
      "dynamic" : "strict",  # old_template_2 的配置
      "properties" : {
        "ip" : {
          "type" : "ip"
        }
      }
    },
    "settings" : {
        "refresh_interval" : "10s",
        "number_of_shards" : "2",
        "provided_name" : "temp-test",
        "creation_date" : "1620617979932",
        "number_of_replicas" : "1",
        "uuid" : "RwvrdGziT7iVmVutXYPwqA",
        "version" : {
          "created" : "7100099"
        }
      }
    }
  }
}

1、#1 处我们创建了 1 个新版本的索引模板匹配名字,以template开头的索引,设置可以动态增加属性并设置别名new-template


2、#2 处我们创建了 1 个老版本的索引模板匹配名字,以temp开头的索引,设置不动态增加属性并设置别名old_template_1

3、#3 处我们创建了 1 个老版本的索引模板匹配名字,以temp-开头的索引,设置有新增属性时报错并设置别名old_template_2,同时配置order为10

4、#4 处我们创建了 1 个名为template-test的索引

5、#5 处查看索引template-test的配置,该名称会匹配新版new_template模板,和老版

old_template_1模板,根据索引的别名信息,只有新版模板配置的别名可以看出,该索引仅仅应用了new_template模板

6、#6 处创建了 1 个名为temp-test的索引

7、#7 处查看索引temp-test的配置,该名称会匹配老版old_template_1old_template_2模板,根据索引的别名信息有old_template_1old_template_1可以看出,2 个模板的配置都应用了。通过dynamic字段为strict我们可以判断该字段使用了order较高的模板old_template_2的配置

 


《Elastic Stack 实战手册》——三、产品能力——3.4.入门篇——3.4.2.Elasticsearch基础应用——3.4.2.8.Index template(8) https://developer.aliyun.com/article/1230793

相关实践学习
以电商场景为例搭建AI语义搜索应用
本实验旨在通过阿里云Elasticsearch结合阿里云搜索开发工作台AI模型服务,构建一个高效、精准的语义搜索系统,模拟电商场景,深入理解AI搜索技术原理并掌握其实现过程。
ElasticSearch 最新快速入门教程
本课程由千锋教育提供。全文搜索的需求非常大。而开源的解决办法Elasricsearch(Elastic)就是一个非常好的工具。目前是全文搜索引擎的首选。本系列教程由浅入深讲解了在CentOS7系统下如何搭建ElasticSearch,如何使用Kibana实现各种方式的搜索并详细分析了搜索的原理,最后讲解了在Java应用中如何集成ElasticSearch并实现搜索。  
相关文章
|
数据处理
基于ARM的嵌入式原理与应用:ALU的功能与特点
基于ARM的嵌入式原理与应用:ALU的功能与特点
2325 0
|
Web App开发 JavaScript 前端开发
JQuery的选择器有哪些?
JQuery的选择器有哪些?
98 1
|
JavaScript 前端开发
JavaScript-jQuery的使用 + JS的案例
JavaScript-jQuery的使用 + JS的案例
172 0
|
Java Maven
Maven下载,本地仓库,远程仓库配置
Maven下载,本地仓库,远程仓库配置
594 0
|
编解码 人工智能 算法
AAAI 2023 Oral | 字节提出非对称图像重采样模型,JPEG、WebP上抗压缩性能领先SOTA
AAAI 2023 Oral | 字节提出非对称图像重采样模型,JPEG、WebP上抗压缩性能领先SOTA
277 0
|
算法 决策智能
BF算法(字符串查找)
BF算法(字符串查找)
276 0
BF算法(字符串查找)
|
计算机视觉
使用 OpenCV 读取、显示和写入图像
使用 OpenCV 读取、显示和写入图像
594 0
|
Cloud Native 云计算
聚焦云原生 | 2022 飞天技术峰会火热报名中!
有一种速度,叫深圳速度,当加入了云计算,这个速度,就被赋予了新的内涵。2022 年 8 月 11 日,阿里云飞天技术峰会正式开幕!等你到来。
聚焦云原生 | 2022 飞天技术峰会火热报名中!
|
存储 SQL 关系型数据库
如何选择高速存储、查询数据库
作者:方圆链接:https://www.zhihu.com/question/20010554/answer/15863274来源:知乎著作权归作者所有,转载请联系作者获得授权。 一、 PostgreSQL 的稳定性极强, Innodb 等引擎在崩溃、断电之类的灾难场景下抗打击能力有了长足进步,然而很多 MySQL 用户都遇到过Server级的数据库丢失的场景——mysql系统库是MyISAM的,相比之下,PG数据库这方面要好一些。
1706 0

热门文章

最新文章