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

Elasticsearch导出导入数据

1.概念回顾

2.基础操作

展示详细信息

GET:http://127.0.0.1:9200/_cat/indices?v

Java代码将文件导入到ES

package com.Graph.medicalgraph;import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;//导入es
public class JSONDataImporter {public static void main(String[] args) {String jsonFilePath = "D:\\xx.json";String indexName = "test01";try (RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http")))) {BulkRequest bulkRequest = new BulkRequest();BufferedReader reader = new BufferedReader(new FileReader(jsonFilePath));String line;int id = 0;while ((line = reader.readLine()) != null) {IndexRequest indexRequest = new IndexRequest(indexName);indexRequest.source(line, XContentType.JSON);indexRequest.id(Integer.toString(id++)); // 使用递增IDbulkRequest.add(indexRequest);}BulkResponse bulkResponse = client.bulk(bulkRequest, RequestOptions.DEFAULT);if (bulkResponse.hasFailures()) {System.out.println("Some documents failed to import.");} else {System.out.println("All documents imported successfully.");}} catch (IOException e) {e.printStackTrace();}}
}

全查询:http://127.0.0.1:9200/indexName_test01/_search


http://www.mrgr.cn/news/33510.html

相关文章:

  • Flyway 基本概念
  • 【深入Java枚举类:不仅仅是常量的容器】
  • 小红书笔记采集器
  • js进阶——函数作用域和块作用域
  • Centrality
  • 【WSL迁移】将WSL2迁移到D盘
  • 《鸿蒙应用开发实战》关注公众号抽奖
  • 深入浅出:Eclipse 中配置 Maven 与 Spark 应用开发全指南
  • 计算机毕业设计之:基于深度学习的路面检测系统(源码+部署文档+讲解)
  • Apache CVE-2021-41773 漏洞攻略
  • Linux网络命令
  • 秒变 Vim 高手:必学的编辑技巧与隐藏功能大揭秘
  • ActivityManagerService bindService(7)
  • 第十四章:html和css做一个心在跳动,为你而动的表白动画
  • ARM(Day 1)思维导图
  • EECS498 Deep Learning for Computer Vision (一)软件使用指南
  • 【Webpack--015】打包速度优化--loader配置oneOf
  • 江上场景目标检测系统源码分享
  • [mongodb][备份]MongoDBBak.bat
  • 【C++前缀和 排序】2171. 拿出最少数目的魔法豆|1748