弹性搜索获取索引模板



我想通过rest调用来找出索引绑定到哪个模板。所以基本上传递索引名称并获取它属于哪个模板。

基本上,我知道我可以列出所有模板,并通过模式查看哪些索引将绑定到模板,但我们有太多的模板和太多的排序,很难判断。

您可以为此使用_meta映射字段,以便将任何自定义信息附加到索引中。

假设你有一个像这样的索引模板

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
},

最新更新