【es】使用模版组件简化模版配置

1.模版组件 
可以把常规的索引设置,映射等内容写成可复用的模板组件,然后在索引模板中引用这些组件。
这样模板中的配置内容就会非常简洁。

2.使用模板组件 
#创建一个组件模板:

curl  -u elastic:elastic  -k -XPUT "http://192.168.1.800:9200/_component_template/comp1 " -H 'Content-Type: application/json' -d  '
{
 "template":{
   "mappings":{
    "properties":{
	  "content":{"type":"text"}
	}
   }
 }
}'

#再创建一个组件模板,配置了别名 loginfo,主分片数为3,每个主分片的副本数2;
curl  -u elastic:elastic  -k -XPUT "http://192.168.1.800:9200/_component_template/comp2" -H 'Content-Type: application/json' -d  '
{
 "template":{
   "settings":{
    "number_of_shards":"3",
	"number_of_replicas":"2"
	},
	"aliases":{"loginfo":{}}
   }
 }
}'

#创建一个索引模板引用组件模板。
#curl  -u elastic:elastic  -k -XDELETE "http://192.168.1.800:9200/_index_template/info_model"
curl  -u elastic:elastic  -k -XPUT "http://192.168.1.800:9200/_index_template/info_model" -H 'Content-Type: application/json' -d  '
{
 "index_patterns":["loginfo*"],
 "priority":200,
 "composed_of":["comp1","comp2"]
}'


#创建索引 
curl  -u elastic:elastic  -k -XDELETE "http://192.168.1.800:9200/loginfo1"
curl  -u elastic:elastic  -k -XPUT "http://192.168.1.800:9200/loginfo1"
curl  -u elastic:elastic  -k -XGET "http://192.168.1.800:9200/loginfo1"
{
    "loginfo1":{
        "aliases":{
            "loginfo":{

            }
        },
        "mappings":{
            "properties":{
                "content":{
                    "type":"text"
                }
            }
        },
        "settings":{
            "index":{
                "routing":{
                    "allocation":{
                        "include":{
                            "_tier_preference":"data_content"
                        }
                    }
                },
                "number_of_shards":"3",
                "provided_name":"loginfo1",
                "creation_date":"1743661458187",
                "number_of_replicas":"2",
                "uuid":"6A2UqFGYT2eNHHG0_g52XQ",
                "version":{
                    "created":"7170099"
                }
            }
        }
    }
}

由此可见:comp1,comp2两个组件模板在内容都继承了

#删除索引模版 
curl  -u elastic:elastic  -k -XDELETE "http://192.168.1.800:9200/_index_template/info_model"
#删除组件模版:
curl  -u elastic:elastic  -k -XDELETE "http://192.168.1.800:9200/_component_template/comp1"
curl  -u elastic:elastic  -k -XDELETE "http://192.168.1.800:9200/_component_template/comp2"

注意: 
当多个组件模版中存在重复的配置内容时,后面的组件模版会覆盖前面的组件模版内容。
如果一个组件模版正在被某个索引模版引用,则这个组件模版不可以被删除。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值