elasticsearch 索引模板 index template 的使用

Index template 定义在创建新 index 时可以自动应用的 settings 和 mappings。 Elasticsearch 根据与 index 名称匹配的 index 模式将模板应用于新索引。这个对于我们想创建的一系列的 Index 具有同样的 settings 及 mappings。比如我们希望每一天/月的日志的index都具有同样的设置。

  1. 创建一个模板
PUT _index_template/ellis
{
  "index_patterns": ["ellis*"],
  "template":
  {
    "settings":
    {
      "number_of_shards": 1
    },
    "mappings":{
      "properties": {
        "host_name": {
          "type": "keyword"
        },
        "created_at": {
          "type": "date",
          "format": "EEE MMM dd HH:mm:ss Z yyyy"
        }
      }
    },
    "aliases": {
      "mydata": { }
    }
  },
   "priority":20
}

priority可选配置,创建新索引时确定索引模板优先级(针对多个模板匹配)。选择具有最高优先级的索引模板。如果未指定优先级,则将模板视为优先级为0(最低优先级)
aliases 是要设置的别名

  1. 查询index 是否存在
HEAD _index_template/ellis
  1. 删除模板
DELETE _index_template/ellis

参考
https://www.elastic.co/guide/en/elasticsearch/reference/current/index-templates.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值