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

导出ES数据到excel

首先通过elasticdump组件将线上指定的index导出成文本文件
elasticdump --input=“http://192.168.0.30:9200/adv_default” --output=“/bigdata/adv_default.data” --type=data --li
————————————————

数据结构如下

{

"_id": "LzGZS5IBxuIn9SX3wAIs",
"_index": "ods_data_vsahuman_202410",
"_score": 1,
"_source": {
"ageRegion": "1",
"capStyle": "0",
"cateCode": "vsahuman",
"coatColor": "1",
"coatStyle": "0",
"coatTexture": "0",
"collectPicture": false,
"collectTime": "2024-10-02 13:00:20",
"dataId": "1841342429132345344",
"deviceID": "61030300002006000212",
"deviceName": "大庆路人民保险公司门口",
"deviceNo": "61030300002006000212",
"genderCode": "1",
"glasses": "0",
"hairStyle": "2",
"hat": "0",
"inStorage": false,
"locationMarkTime": "1727845208000",
"personID": "1841342429132345344",
"sourceCode": "zhongke",
"sourceType": 1,
"standardCode": "video",
"storageUrl1": "http://10.45.58.111:9000/citmsism-person/2024/10/02/13/00/41ec75053b2de4e5b7d474dd3ac5ee9b.jpg",
"storageUrl2": "http://10.45.58.111:9000/citmsxva/202410/02/1300/JSJkbKcrEy20241002T130008ZVQmk.jpg",
"storageUrl3": "http://10.45.58.111:9000/citmsxva/202410/02/1300/JSJkbKcrEy20241002T130008ZVQmk.jpg",
"transformTime": "2024-10-02 13:00:08",
"trousersColor": "1"
},
"_type": "citms_data"
}

利用java将文件转为excel

public static void main(String[] args) throws IOException {
    // 假设data文件是一个文本文件,每行是一个Excel行
    File dataFile = new File("C:\\Users\\tytu\\Desktop\\fsdownload\\es-data\\ods_data_vsanonmotorvehicle_202410.data");
    Workbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet("Data");
    // 读取data文件并写入Excel
    try (BufferedReader reader = new BufferedReader(new FileReader(dataFile))) {
        int rowNum = 0;
        while (reader.ready()) {
            String json = reader.readLine();
            JSONObject jsonObject = JSONObject.parseObject(json, JSONObject.class);
            JSONObject source = jsonObject.getJSONObject("_source");
            Row row = sheet.createRow(rowNum);
            if (rowNum == 0) {
                int colNum2 = 0;
                for (String s : source.keySet()) {
                    Cell cell = row.createCell(colNum2);
                    cell.setCellValue(s);
                    ++colNum2;
                }
            } else {

                int colNum3 = 0;
                for (Object value : source.values()) {
                    Cell cell = row.createCell(colNum3);
                    if (value == null) {
                        cell.setCellValue("");
                    } else {
                        cell.setCellValue(value.toString());
                    }
                    ++colNum3;
                }
            }
            ++rowNum;
        }
    }
    // 写入Excel文件
    String f=   dataFile.getPath();
    String substring = f.substring(0, f.lastIndexOf("."));
    try (FileOutputStream outputStream = new FileOutputStream(substring+".xlsx")) {
        workbook.write(outputStream);
    }

    System.out.println("Data written to Excel successfully.");
}

通过python脚本



```python
import json
import pandas as pd
json_file_path = 'C:\\Users\\tytu\\Desktop\\fsdownload\\ods_data_vsahuman_202410.data'
with open(json_file_path, 'r', encoding='utf-8') as file:
    json_data = file.readlines()
data_list = []
for line in json_data:
    json_line = json.loads(line)
    source_data = json_line['_source']
    data_list.append(source_data)
df = pd.DataFrame(data_list)
excel_output_file = json_file_path.split('.')[0] + '.xlsx'
df.to_excel(excel_output_file, index=False)

http://www.kler.cn/news/341332.html

相关文章:

  • HashMap 和 Hashtable 有什么区别?
  • 基于Springboot vue应急物资供应管理系统设计与实现
  • Python 代码执行失败问题及解决方案
  • 基于遗传粒子群算法的无人机路径规划【遗传算法|基本粒子群|遗传粒子群三种方法对比】
  • 代码随想录day25:贪心part3
  • JavaScript 命令模式实战:打造可撤销的操作命令
  • C语言 | Leetcode C语言题解之第460题LFU缓存
  • Java日志(总结)
  • K8sGPT 实战:智能化 Kubernetes 集群诊断与问题解决
  • Windows 11 24H2版本有哪些新功能_Windows 11 24H2十四大新功能介绍
  • 【Fine-Tuning】大模型微调理论及方法, PytorchHuggingFace微调实战
  • 《webpack深入浅出系列》
  • 【论文阅读】DeepAC:实时六自由度目标跟踪的深度主动轮廓
  • Linux如何将驱动文件编译成独立的模块或者编译到内核?
  • 缓存数据一致性保证通用方案
  • Linux下Nodejs应用service配置
  • LeetCode讲解篇之377. 组合总和 Ⅳ
  • 矩阵式键盘接口设计(用单片机读取4x4矩阵式键盘的键号,并将其显示在数码管上)(Proteus 与Keil uVision联合仿真)
  • 【网络安全】账户安全随笔
  • Vue82 路由器的两种工作模式 以及 node express 部署前端