利用_reindex和_aliases伪修改mapping内容

一、使用背景

索引创建后不能对mapping进行修改,但具有修改mapping的需求。

二、实现过程

1、新建相似index

2、将原来index中数据复制到新索引,通过reindex接口

3、为新建的索引创建一个原来索引的别名——以保证之前的查询条件不改变,然后删除原索引

三、分步骤实现

前言

原索引为nba,其中name中的index为false:index为false的字段是不能作为查询条件的,而此时想通过name字段进行搜索,于是需要修改mapping

{ "nba": { "aliases": { }, "mappings": { "_doc": { "properties": { "jerse_no": { "type": "keyword" }, "name": { "type": "text", "index":"false" }, "play_year": { "type": "keyword" }, "position": { "type": "keyword" }, "team_name": { "type": "text" } } } }, "settings": { "index": { "creation_date": "1621844156710", "number_of_shards": "5", "number_of_replicas": "1", "uuid": "0tNlkuGSSsepjidLaNXFGg", "version": { "created": "6040399" }, "provided_name": "nba2", } } }

1、新建相似index——nba2,nba2中name字段的index为默认值true

{ "nba2": { "aliases": { "nba": {} }, "mappings": { "_doc": { "properties": { "jerse_no": { "type": "keyword" }, "name": { "type": "text" }, "play_year": { "type": "keyword" }, "position": { "type": "keyword" }, "team_name": { "type": "text" } } } }, "settings": { "index": { "creation_date": "1621844156710", "number_of_shards": "5", "number_of_replicas": "1", "uuid": "0tNlkuGSSsepjidLaNXFGg", "version": { "created": "6040399" }, "provided_name": "nba2" } } } }

2、通过_reindex接口将nba中的数据复制到nba2中

POST _reindex { "source": { "index": "nba" }, "dest": { "index": "nba2" } }

3、通过_aliases为新建的索引创建一个原来索引的别名,然后删除原索引

POST /_aliases { "actions" : [ { "add": { "index": "nba2", "alias": "nba" } }, { "remove_index": { "index": "nba" } } ] }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值