我想通过 rest 调用找出索引绑定到哪个模板。所以基本上就是传递索引名,获取属于哪个模板。
基本上,我知道我可以列出所有模板并通过模式查看哪些索引将绑定到模板,但是我们有太多的模板和太多的排序,很难说。
答案 0 :(得分:0)
您可以使用 _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
},