创建索引模板,所有以people_trail开头的索引都会走这个索引模板
curl -DPUT '127.0.0.1:9200/_template/people_trail' -d '{
"template": "people_trail*",
"settings": {
"index": {
"number_of_shards": "1",
"number_of_replicas": "0",
"analysis": {
"analyzer": {
"pinyin": {
"tokenizer": "pinyin_tokenizer"
}
},
"tokenizer": {
"pinyin_tokenizer": {
"type": "pinyin",
"keep_joined_full_pinyin": true
}
}
}
}
},
"mappings": {
"_default_": {
"_all": {
"enabled": true,
"analyzer": "standard"
},
"dynamic_templates": [
{
"xms": {
"mapping": {
"fields": {
"py": {
"analyzer": "pinyin",
"type": "text"
}
},
"type": "keyword"
},
"match_mapping_type": "string",
"match": "XM"
}
},
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "keyword",
"fields": {
"full": {
"type": "text",
"analyzer": "standard"
}
}
}
}
}
]
}
}
}'
查询所有模板
curl -XGET 127.0.0.1:9200/_cat/templates
curl -XGET 127.0.0.1:9200/_cat/templates
address_type address_type* 0
article_type* article_type* 0
people_trail people_trail* 0
article_type lw_* 0
查看某一个模板
curl -XGET http://127.0.0.1:9200/_template/article_type?pretty
curl -XGET http://127.0.0.1:9200/_template/article_type?pretty
{
"article_type" : {
"order" : 0,
"template" : "lw_*",
"settings" : {
"index" : {
"analysis" : {
"analyzer" : {
"pinyin" : {
"tokenizer" : "pinyin_tokenizer"
}
},
"tokenizer" : {
"pinyin_tokenizer" : {
"type" : "pinyin",
"keep_joined_full_pinyin" : "true"
}
}
}
}
},
"mappings" : {
"_default_" : {
"dynamic_templates" : [
{
"xms" : {
"mapping" : {
"fields" : {
"py" : {
"analyzer" : "pinyin",
"type" : "text"
}
},
"type" : "keyword"
},
"match_mapping_type" : "string",
"match" : "XM"
}
},
{
"strings" : {
"mapping" : {
"type" : "keyword",
"fields" : {
"full" : {
"analyzer" : "standard",
"type" : "text"
}
}
},
"match_mapping_type" : "string"
}
}
],
"_all" : {
"analyzer" : "standard",
"enabled" : true
}
}
},
"aliases" : { }
}
}
删除一个索引模板
curl -XDELETE http://127.0.0.1:9200/_template/article_type
curl -XDELETE http://127.0.0.1:9200/_template/article_type
{"acknowledged":true}