ElasticSearch(六):索引模板

ElasticSearch(六):索引模板

学习课程连接《Elasticsearch核心技术与实战》html

<br/> ## Index Template * Index Template - 帮助你设定`Mappings`和`Settings`,并按照必定的规则,自动匹配到新建立的索引上 - 模板仅在一个索引被建立时,才会产生做用。修改模板不会影响已建立的索引 - 你能够设定多个索引模板,这些设置会被`merge`在一块儿 - 你能够指定`order`的数值,控制`merging`的过程app

#示例一:对全部的索引有效
PUT _template/template_default
{
  "index_patterns": ["*"],
  "order" : 0,
  "version": 1,
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas":1
  }
}
#示例二:对以test开头索引有效
PUT /_template/template_test
{
    "index_patterns" : ["test*"],
    "order" : 1,
    "settings" : {
    	"number_of_shards": 1,
        "number_of_replicas" : 2
    },
    "mappings" : {
    	"date_detection": false,
    	"numeric_detection": true
    }
}
#查看template信息
GET /_template/template_default
GET /_template/temp*
#删除template信息
DELETE /_template/template_default
DELETE /_template/template_test
  • 如何使用 Index Template,当一个索引被建立时
    • 默认应用Elasticsearch默认的settingsmappings
    • 而后应用order数值低的 IndexTemplate 中的设定
    • 再应用order数值高的 IndexTemplate 中的设定,以前的设定会被覆盖
    • 最后应用建立索引时,用户所指定的settingsmappings,并覆盖以前模板中的设定

<br/> ## Dynamic Template Dynamic Template 是定义在具体索引`mappings`中的,根据Elasticsearch识别的数据类型,结合字段名称,来动态设定字段类型: * 全部的字符串类型都设定成`keyword`,或者关闭`keyword`字段 * `is`开头的字段设置成`boolean` * `long_`开头的都设置成`long`类型学习

#示例一:Dynaminc Mapping 根据类型和字段名
PUT my_index
{
  "mappings": {
    "dynamic_templates": [
      {
          "strings_as_boolean": {
          "match_mapping_type":   "string",
          "match":"is*",
          "mapping": {
            "type": "boolean"
          }
        }
      },
      {
        "strings_as_keywords": {
          "match_mapping_type":   "string",
          "mapping": {
            "type": "keyword"
          }
        }
      }
    ]
  }
}
#示例二:
PUT my_index
{
  "mappings": {
    "dynamic_templates": [
      {
        "full_name": {
          "path_match":   "name.*",
          "path_unmatch": "*.middle",
          "mapping": {
            "type":       "text",
            "copy_to":    "full_name"
          }
        }
      }
    ]
  }
}

<br/>spa

原文出处:https://www.cnblogs.com/czbxdd/p/11843489.htmlcode

相关文章
相关标签/搜索