SpringBoot ES 重建 Mapping

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;

/**
 * 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:123456@127.0.0.1:9200/_reindex
{
   
    "source": {
   
        "index": "备份索引名称"
    },
    "dest": {
   
        "index": "新索引名称"
    }
}

相关推荐

  1. SpringBoot ES 重建 Mapping

    2024-01-21 09:12:01       54 阅读
  2. springboot 重新注册 bean

    2024-01-21 09:12:01       24 阅读
  3. springboot中的一些重要的注解

    2024-01-21 09:12:01       43 阅读
  4. SpringBoot表单防止重复提交

    2024-01-21 09:12:01       38 阅读
  5. springboot防止表单重复提交

    2024-01-21 09:12:01       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-21 09:12:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-21 09:12:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-21 09:12:01       82 阅读
  4. Python语言-面向对象

    2024-01-21 09:12:01       91 阅读

热门阅读

  1. FPGA中为什么不能双时钟触发

    2024-01-21 09:12:01       55 阅读
  2. RPC教程 2.支持并发与异步的客户端

    2024-01-21 09:12:01       52 阅读
  3. QGraphicsView 如何让图形大小适配窗口

    2024-01-21 09:12:01       48 阅读
  4. OSPF:开放式最短路径优先协议

    2024-01-21 09:12:01       47 阅读
  5. 【机器学习300问】13、学习率曲线有什么作用?

    2024-01-21 09:12:01       55 阅读