当前位置: 首页 > news >正文

实现一键不同环境迁移ES模板

实现概述:

1、查询环境A模板信息

2、获取模板信息值转换

3、同步保存至环境B

package com.jayce.boot.route.common.util;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Lists;
import com.jayce.boot.route.common.util.superClient.JsonUtil;
import com.jayce.boot.route.common.util.superClient.SuperClientUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 实现ES模板从环境A,同步到B
 *
 * @author sunjie
 * @datetime 2025/3/8 10:51
 **/
public class EsTemplateSyncUtil {
    public static void main(String[] args) {
        List<String> taskList = Lists.newArrayList("tempalte1",
                "tempalte2",
                "tempalte3");

        for (String taskNo : taskList) {
            sync(taskNo);
        }
    }

    public static Boolean sync(String templateName) {
        //查询模板
        try {
            System.out.println(">>>>>>>>>>>>>>>>>>" + templateName + " GET TEMPLATE");
            Map<String, String> header = new HashMap<>();
            header.put("Authorization", "Basic xxxxxxx");
            JsonNode jsonNode = SuperClientUtil.ipHttpGet("http://环境A:9200", "/_template/" + templateName, header);
            System.out.println(jsonNode);

            //解析参数
            Map<String, Object> map = JsonUtil.nodeToEntity(jsonNode, Map.class);
            Object paramObj = map.get(templateName);

            //同步到新环境
            Map<String, String> header2 = new HashMap<>();
            header2.put("Authorization", "Basic xxxxxxx");
            templateName = templateName.replace("*", "");
            JsonNode jsonNode2 = SuperClientUtil.ipHttpPost("http://环境B:9200", "/_template/" + templateName, JsonUtil.toJsonString(paramObj), header2);
            System.out.println("ES response:" + jsonNode2);
            System.out.println("<<<<<<<<<<<<<<<<<<" + templateName + " SYNC SUCCESS!");
        } catch (Exception e) {
            System.out.println("<<<<<<<<<<<<<<<<<<" + templateName + " SYNC FAIL!!!!!!!!");
        }
        return true;
    }
}

相关文章:

  • 在IDEA中进行git回滚操作:Reset current branch to here‌或Reset HEAD
  • pyqt联合designer的运用和设置
  • 2025年全球生成式AI消费应用发展趋势报告
  • Lucas定理介绍及证明
  • 深入理解 Java 中的 CopyOnWrite 机制
  • 解决电脑问题(1)——硬件问题
  • manus本地部署使用体验
  • 「DataX」数据迁移-IDEA运行DataX方法总结
  • 实现插入排序
  • 【leetcode hot 100 234】回文链表
  • manus对比ChatGPT-Deep reaserch进行研究类学术相关数据分析!谁更胜一筹?
  • K8s 端口转发实战指南(Practical Guide to k8s Port Forwarding)
  • 软件性能测试深度解析(进阶篇):JMeter高阶应用与性能工程体系构建
  • Spring Framework中的IoC容器
  • 深度优先搜索(DFS)和广度优先搜索(BFS)——c#实现
  • 如何验证邮件列表的有效性?
  • 从高资源到低资源语言的全覆盖:Manus AI的数据革命与迁移学习策略
  • 计算机组成原理:进位计数制与进制转换
  • #9 【code】实现扩散模型的一个jupyter notebook
  • 二、Visual Studio2022配置OpenGL环境
  • 邹城建设银行网站/广告牌
  • wordpress首页摘要设置/seo怎样
  • pdf怎么做电子书下载网站/by72777最新域名查询
  • 北京有一个公司打电话做网站认证/个人网站该怎么打广告
  • 辽宁省建设厅安全员考试官方网站/市场营销的策划方案
  • 旅行网站开发需求说明书/网络营销与直播电商学什么