Elasticsearch索引模板
warning:
这篇文章距离上次修改已过185天,其中的内容可能已经有所变动。
在Elasticsearch中,索引模板(Index templates)是定义如何创建索引的预配置模式。它们允许你指定设置、映射和别名,这些设置会在索引创建时自动应用。
以下是一个Elasticsearch索引模板的示例,它定义了一个索引模板,该模板适用于所有以logstash-
开头的索引,指定了索引的分片和副本数量,并定义了一个字符串字段的动态映射:
PUT _template/logstash_index_template
{
"index_patterns": ["logstash-*"],
"settings": {
"number_of_shards": 5,
"number_of_replicas": 1
},
"mappings": {
"dynamic_templates": [
{
"string_fields": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
]
}
}
在这个例子中,所有以logstash-
开头的索引在创建时都会自动应用这个模板中定义的设置和映射。这样,你可以集中管理索引的配置,而不是为每个索引单独配置。
评论已关闭