elasticsearch template 模板

本文详细介绍了Elasticsearch的模板功能,包括如何创建一个用于nginx日志的模板,强调了索引创建后主分片数量不可更改但副本数量可以调整的关键点,并探讨了模板的管理策略。通过Postman进行实际操作演示。
摘要由CSDN通过智能技术生成

template 官方文档

创建nginx模板

  • 应用到nginx-* 开头的索引
  • 设置分片数量为 3
  • 分片副本数量为 1
  • 版本号为 1
PUT  /_template/nginx
{

  "template":"nginx-*",
  "settings" : {
    "index.number_of_shards" : 3,
    "number_of_replicas" : 1,
    "index.refresh_interval" : "60s"
  },
  "version"  : 1
}

索引一经创建无法修改主分片数量仅可修改副本

PUT nginx-2017.01.17/_settings
{

    "index.number_of_shards" : 2,
    "number_of_replicas" : 1

}


返回的错误信息如下:
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "can't change the number of shards for an index"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "can't change the number of shards for an index"
  },
  "status": 400
}

管理模板

查看:
[root@ ~]# curl http://localhost:9200/_template/nginx?pretty
或
[root@ ~]# curl http://localhost:9200/_template/nginx | python -mjson.tool
注: pretty 参数仅仅是指定Elasticsearch返回JSON格式结果
{
    "nginx": {
        "aliases": {},
        "mappings": {},
        "order": 0,
        "settings": {
            "index": {
                "number_of_replicas": "1",
                "number_of_shards": "3",
                "refresh_interval": "60s"
            }
        },
        "template": "nginx-*",
        "version": 1
    }
}



删除:
curl -XDELETE localhost:9200/_template/template_1  

  • 使用 postman
    这里写图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值