【发布时间】:2021-06-12 11:45:43
【问题描述】:
我想通过 rest 调用找出索引绑定到哪个模板。所以基本上是通过索引名,得到它属于哪个模板。
基本上,我知道我可以列出所有模板并通过模式查看哪些索引将绑定到模板,但是我们有太多模板和太多排序,很难说。
【问题讨论】:
标签: elasticsearch elastic-stack
我想通过 rest 调用找出索引绑定到哪个模板。所以基本上是通过索引名,得到它属于哪个模板。
基本上,我知道我可以列出所有模板并通过模式查看哪些索引将绑定到模板,但是我们有太多模板和太多排序,很难说。
【问题讨论】:
标签: elasticsearch elastic-stack
您可以为此使用_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
},
【讨论】: