共計 1275 個字符,預計需要花費 4 分鐘才能閱讀完成。
這篇文章主要講解了“Elasticsearch 索引模板 index templates 怎么創建”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著丸趣 TV 小編的思路慢慢深入,一起來研究和學習“Elasticsearch 索引模板 index templates 怎么創建”吧!
一、
索引模板,定義模板,當新索引創建時,自動匹配,并應用定義的模板
新增索引模板 (index templates)
我們新建一個索引模板 template_1 設置它的主分片為 1 個。類型有 type1 且_source disabled
PUT /_template/template_1
template : t-* ,
settings : {
number_of_shards :1
},
mappings : {
type1 :{
_source :{
enabled :false
}
}
}
POST /t-1
GET /t-1/_mapping
t-1 : {
mappings : {
type1 : {
_source : {
enabled : false
},
properties : {}
}
}
}
}
例子:我們想再創建某個索引時,還為其創建 alias
PUT /_template/template_2
template : s-* ,
settings : {
number_of_shards :1
},
aliases :{
alias1 :{
},
{index}-alias :{
}
}
POST /s-1
GET /s-1
當創建多個索引模板時,且創建某個索引,被多個索引模板匹配,那么 settings 和 mappings 將會合并到一個配置中,并應用這個索引上,合并的順序由索引模板的 order 屬性來控制。order 大的會覆蓋之前的配置
PUT /_template/template_1
template : * ,
order :0,
settings :{
number_of_shards :1
},
mappings :{
type1 :{
_source :{
enabled :false
}
}
}
PUT /_template/template_2
template : tt-* ,
order :1,
settings :{
number_of_shards :1
},
mappings :{
type1 :{
_source :{
enabled :true
}
}
}
POST /tt-1 = 會被上述兩個模板都匹配,對于_source 屬性 order= 1 的會覆蓋 order=0 即 enabled:true
文件配置:我們可以再 config/templates 目錄下添加 json 的配置文件
感謝各位的閱讀,以上就是“Elasticsearch 索引模板 index templates 怎么創建”的內容了,經過本文的學習后,相信大家對 Elasticsearch 索引模板 index templates 怎么創建這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關知識點的文章,歡迎關注!