elasticsearch索引模板

创建索引模板

索引模板就是创建好一个索引参数设置(settings)和映射(mapping)的模板,在创建新索引的时候指定模板名称就可以使用模板定义好的参数设置和映射。例如:

PUT _template/mytemplate
{
  "index_patterns": "mylog*",
  "settings": {
    "number_of_shards": 5,
    "number_of_replicas": 2
  },
  "mappings": {
    "type": {
      "properties": {
        "name": {
          "type": "keyword"
        },
        "age": {
          "type": "keyword"
        }
      }
    }
  }
}

模板名称是mytemplate,定义好模板可以使用mylog*来适配,分片数量5,副本数量2,默认文档类型是type

删除模板

DELETE _template/mytemplate

获取模板

得到所有的模板:GET _template/
使用通配符或逗号分割:GET _template/my*

使用模板

当在添加数据时,指定索引名匹配index_patterns时,ES就会自动为数据新建一个索引。

发布了526 篇原创文章 · 获赞 2 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/vincent_duan/article/details/103782447