Elasticsearch获取索引模板
Elastic search get the index template
我想通过 rest 调用找出索引绑定到哪个模板。所以基本上通过索引名称,得到它属于哪个模板。
基本上,我知道我可以列出所有模板并通过模式查看哪些索引将绑定到模板,但是我们有太多的模板和太多的顺序,很难说清楚。
您可以为此使用 _meta
mapping field 以便将任何自定义信息附加到您的索引。
假设您有一个这样的索引模板
PUT _index_template/template_1
{
"index_patterns": ["index*"],
"template": {
"settings": {
"number_of_shards": 1
},
"mappings": {
"_meta": { <---- add this
"template": "template_1" <---- add this
}, <---- add this
"_source": {
"enabled": true
},
"properties": {
"host_name": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z yyyy"
}
}
},
"aliases": {
}
},
"_meta": {
"description": "my custom template"
}
}
一旦您创建了匹配该模板模式的索引,_meta
字段也会将其添加到您正在创建的新索引中。
PUT index1
然后,如果您获得新的索引设置,您将看到它是从哪个模板创建的:
GET index1?filter_path=**._meta.template
=>
{
"index1" : {
"mappings" : {
"_meta" : {
"template" : "template_1" <---- you get this
},
我想通过 rest 调用找出索引绑定到哪个模板。所以基本上通过索引名称,得到它属于哪个模板。
基本上,我知道我可以列出所有模板并通过模式查看哪些索引将绑定到模板,但是我们有太多的模板和太多的顺序,很难说清楚。
您可以为此使用 _meta
mapping field 以便将任何自定义信息附加到您的索引。
假设您有一个这样的索引模板
PUT _index_template/template_1
{
"index_patterns": ["index*"],
"template": {
"settings": {
"number_of_shards": 1
},
"mappings": {
"_meta": { <---- add this
"template": "template_1" <---- add this
}, <---- add this
"_source": {
"enabled": true
},
"properties": {
"host_name": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z yyyy"
}
}
},
"aliases": {
}
},
"_meta": {
"description": "my custom template"
}
}
一旦您创建了匹配该模板模式的索引,_meta
字段也会将其添加到您正在创建的新索引中。
PUT index1
然后,如果您获得新的索引设置,您将看到它是从哪个模板创建的:
GET index1?filter_path=**._meta.template
=>
{
"index1" : {
"mappings" : {
"_meta" : {
"template" : "template_1" <---- you get this
},