elasticsearch 修改mapping映射字段

1. 创建一个中间索引

#创建索引 PUT demo_metric_1/

查看原有字段动态映射类型

GET http://localhost:9002/index[索引名]/_mapping

创建Mapping

POST demo_metric_1/type/_mapping { “type”: { “properties”: { “log_time_date”: { “type”: “date”, “format”: “epoch_millis” }, … } } }

2. 向中间索引备份源索引的数据

重建索引

POST _reindex { “source”: { “index”: “demo_metric” }, “dest”: { “index”: “demo_metric_1” } }

3.查询确认数据是否copy过去

GET /demo_metric/type/_search

GET /demo_metric_1/type/_search

4.删除有问题的索引

删除有问题的索引

DELETE demo_metric

5.重新创建同名的索引(★字段类型修改正确★)

#创建索引 PUT demo_metric/

创建Mapping

POST demo_metric/type/_mapping { “type”: { “properties”: { “log_time_date”: { “type”: “date”, “format”: “epoch_millis” }, … } } }

6. 从中间索引还原到源索引的数据

重建索引

POST _reindex { “source”: { “index”: “demo_metric_1” }, “dest”: { “index”: “demo_metric” } }

7. 删除中间索引

DELETE demo_metric_1

经验分享 程序员 微信小程序 职场和发展