Sprin
gBoot ES 重建 Mapping
- 1 复制数据
- 2 删除老索引
- 3 重建索引
- 4 复制回数据
1 复制数据
POST http://elastic:[email protected]:9200/_reindex
{
"source": {
"index": "老索引名称"
},
"dest": {
"index": "备份索引名称"
}
}
2 删除老索引
DELETE http://elastic:[email protected]:9200//aicc_spp_audio_800808618
3 重建索引
package org.jeecg.modules.mark.common.es.setting;
import lombok.Data;
/**
* ElasticSearch 索引设置
*
* @date 2023年12月21日09点47分
* @since V1.0.0.0
*/
@Data
public class ElasticSearchSetting {
/**
* 是指索引要做多少个分片,只能在创建索引时指定,后期无法修改。
*/
private int number_of_shards = 3;
/**
* 每个分片有多少个副本,后期可以动态修改。
*/
private int number_of_replicas = 1;
/**
* max_result_window 是分页返回的最大数值,默认值为10000。
*/
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:[email protected]:9200/_reindex
{
"source": {
"index": "备份索引名称"
},
"dest": {
"index": "新索引名称"
}
}