ES8导出的mapping批量修改索引名

功能

ES8导出的mapping批量修改索引名,便于冷热生命周期的配置

package com.test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 将ES8的索引批量新增后缀名
 * 去除第三层的type
 */
public class Es8ModifyName {
    public static void main(String[] args) {
        // 获取当前文件夹下所有的 .json 文件
        File folder = new File("C:\\Users\\wyc\\Desktop\\小卫星\\集群维护\\es_mapping");
        File[] files = folder.listFiles((dir, name) -> name.endsWith(".json") && name.startsWith("m"));
//        File[] files = folder.listFiles((dir, name) -> name.endsWith(".json"));
        // 遍历每个文件
        for (File file : files) {
            try {
                // 读取文件内容
                Path path = Paths.get(file.getAbsolutePath());
                byte[] bytes = Files.readAllBytes(path);
                String content = new String(bytes);

                // 解析 JSON 数据
                Object jsonObject = JSON.parse(content, Feature.OrderedField);
                JSONObject newJson = modifyName(jsonObject);
                // 将修改后的 JSON 写回原文件
                String jsonString = JSON.toJSONString(newJson, SerializerFeature.PrettyFormat);
                Files.write(path, jsonString.getBytes());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    private static JSONObject modifyName(Object json) {
        JSONObject newJson = new JSONObject();
        JSONObject jsonObject = (JSONObject) json;
        for (String key : jsonObject.keySet()) {
            Object value = jsonObject.get(key);
            newJson.put(key + "-002024", value);
        }
        return newJson;
    }
}

相关推荐

  1. ES8导出mapping批量修改索引

    2024-04-24 15:02:02       30 阅读
  2. ES6导出mapping结构转为ES8结构

    2024-04-24 15:02:02       31 阅读
  3. 修改ES索引名称

    2024-04-24 15:02:02       25 阅读
  4. 脚本批量导入导出es表结构

    2024-04-24 15:02:02       64 阅读
  5. python-使用ffmpeg批量修改文件后缀

    2024-04-24 15:02:02       53 阅读
  6. es修改mapping映射

    2024-04-24 15:02:02       99 阅读
  7. es创建索引mapping和setting)

    2024-04-24 15:02:02       39 阅读

最近更新

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

    2024-04-24 15:02:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-24 15:02:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-24 15:02:02       82 阅读
  4. Python语言-面向对象

    2024-04-24 15:02:02       91 阅读

热门阅读

  1. GNU nano编辑文件,保存文件

    2024-04-24 15:02:02       27 阅读
  2. 【matlab】灰度图压缩

    2024-04-24 15:02:02       29 阅读
  3. ros的master和apollo的cyber的异同

    2024-04-24 15:02:02       29 阅读
  4. windows10 下 wsl + ubuntu + cups 安装使用

    2024-04-24 15:02:02       32 阅读
  5. 从零开始的机器学习之旅:探索Sklearn基础教程

    2024-04-24 15:02:02       36 阅读
  6. PHP中的错误处理机制是怎样的?

    2024-04-24 15:02:02       75 阅读
  7. 如何根据元素的位置关系来调整 CSS 样式

    2024-04-24 15:02:02       31 阅读
  8. PostCSS概述

    2024-04-24 15:02:02       31 阅读
  9. Ajax的请求响应

    2024-04-24 15:02:02       44 阅读