SpringBoot ES 重建 Mapping
- 1 复制数据
- 2 删除老索引
- 3 重建索引
- 4 复制回数据
1 复制数据
POST http://elastic:123456@127.0.0.1:9200/_reindex
{"source": {"index": "老索引名称"},"dest": {"index": "备份索引名称"}
}
2 删除老索引
DELETE http://elastic:123456@127.0.0.1:9200//aicc_spp_audio_800808618
3 重建索引
package org.jeecg.modules.mark.common.es.setting;import lombok.Data;
@Data
public class ElasticSearchSetting {private int number_of_shards = 3;private int number_of_replicas = 1;private int max_result_window = 20000000;}
@Test
void createIndex() {String indexName = "索引名称";IndexCoordinates index = IndexCoordinates.of(indexName);if (!restTemplate.indexOps(index).exists()) {final Document mapping = restTemplate.indexOps(index).createMapping(AudioMarkInfo.class);mapping.put("date_detection", false);mapping.put("numeric_detection", false);final Document parse = Document.parse(JSONUtil.toJsonStr(new ElasticSearchSetting()));restTemplate.indexOps(index).create(parse);restTemplate.indexOps(index).putMapping(mapping);log.info("ES索引{}不存在,创建ES索引完成!", index.getIndexName());}
}
4 复制回数据
POST http://elastic:123456@127.0.0.1:9200/_reindex
{"source": {"index": "备份索引名称"},"dest": {"index": "新索引名称"}
}