• ES


    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

  • 相关阅读:
    拖拽系列二、利用JS面向对象OOP思想实现拖拽封装
    拖拽系列一、JavaScript实现简单的拖拽效果
    CSS3中三角形及三角形组合图实现
    计算机内存管理介绍
    [Leetcode]双项队列解决滑动窗口最大值难题
    [Leetcode]827.使用回溯+标记解决最大人工岛问题
    计算机启动过程
    [Leetcode]895.最大频率栈
    GDB查看内存(x 命令)
    理解递归
  • 原文地址:https://www.cnblogs.com/huangfox/p/9474339.html
Copyright © 2020-2023  润新知