ES2中关于索引模板的操作

前言

首先这里是关于ES2中对于索引模板的操作记录,对于es6及以上对于索引模板的操作和结构可以看下面的的链接
elastic中es6教程关于索引模板的部分
es6以前和es6以后索引模板结构的区别


一、 创建一个新的索引模板

put  _template/模板名称
{
  "template": "索引模板前缀*",   //匹配的索引名字
  "order": 3,		//代表权重,如果有多个模板的时候,优先进行匹配,值越大,权重越高 
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1
  },
  "mappings": {
    "_default_": {			//默认的配置
      "_source": {				//只关心度量结果,不是原始文件内容
        "enabled": false
      },
      "_all": {					//你确切地知道你对哪个 field 做查询操作
        "enabled": false		
      },
      "dynamic": "strict"		//数据是结构化数据。字段设置严格,避免脏数据注入
    },
    "doc": {
      "_source": {
        "enabled": false
      },
      "properties": {
        "字段名": {
          "type": "字段类型"
        },
        "字段名": {
          "type": "字段类型"
        },
        "字段名": {
          "type": "字段类型"
        }
      }
    }
  }
}

上面索引模板结构的解释可以看下面两个,结构都是差不多的
elastic中es2教程关于索引模板的部分
es5中关于索引模板的介绍

索引模板还有别名,但是我是一般不用,所以就不写了

二、 查看索引模板

1、 查看所有模板

get _template
{}

2、 查看指定的模板

get _template/模板名
{}

3、 模糊匹配

get _template/模板名前缀 + *
{}

4、 批量查询

get /_template/模板名1,模板名2
{}

三、 删除指定模板

delete _template/模板名
{}

四、修改模板(相当于整体替换,重置)

post _template/模板名
{
  "template": "索引模板前缀*",   
  "order": 3,		 
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1
  },
  "mappings": {
    "_default_": {			
      "_source": {				
        "enabled": false
      },
      "_all": {					
        "enabled": false		
      },
      "dynamic": "strict"		
    },
    "doc": {
      "_source": {
        "enabled": false
      },
      "properties": {
        "字段名": {
          "type": "字段类型"
        },
        "字段名": {
          "type": "字段类型"
        },
        "字段名": {
          "type": "字段类型"
        }
      }
    }
  }

五、根据索引模板创建索引

首先创建一个 example* 的索引模板,再根据上面创建索引的方式创建一个 example_2010 索引,这样如果不设置字段,则字段就会和索引模板上的一致,如果在创建索引时加了字段,则字段会合并,取并集

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值