ES重建索引

0

今天发现ES索引建错了,很难受记录一下重建过程:

# 查看索引结构
curl http://elastic:elastic@localhost:9200/index_log

# 新建临时索引
curl -X PUT http://elastic:elastic@localhost:9200/index_log_back

# 拷贝临时索引
curl -X POST -H "Content-Type: application/json" http://elastic:elastic@localhost:9200/_reindex -d '{"source":{"index":"index_log"},"dest":{"index":"index_log_back"}}'

# 查询索引状态
curl http://elastic:elastic@localhost:9200/_cat/indices

# 删除旧的索引
curl -X DELETE http://elastic:elastic@localhost:9200/index_log

# 重启应用建立索引

# 还原数据
curl -X POST -H "Content-Type: application/json" http://elastic:elastic@localhost:9200/_reindex -d '{"source":{"index":"index_log_back"},"dest":{"index":"index_log"}}'

# 删除临时索引
curl -X DELETE http://elastic:elastic@localhost:9200/index_log_back