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

elasticsearch批量导入问题

    @Testvoid bulkIndex() throws IOException{List<Product> products = new ArrayList<Product>();products.add(new Product("香烟",135,1));
//        products.add(new Product("瓜子",154,2));
//        products.add(new Product("矿泉水",613,3));
//        products.add(new Product("酱油",72,4));
//        products.add(new Product("大米",771,5));BulkRequest.Builder bk = new BulkRequest.Builder();int indexId = 4;for (Product product:products) {bk.operations(op->op.index(i->i.index("newindexgst")
//                    .id(UUID.randomUUID().toString()).id("1").document(product)));}BulkResponse response = clint.configClint().bulk(bk.build());if (response.errors()) {System.out.println("Bulk had errors");for (BulkResponseItem item: response.items()) {if (item.error() != null) {System.out.println(item.error().reason());}}}}使用elasticsearch执行java依赖导入没有报错但是发现导入不成功查看日志发现:[newindexgst][0] primary shard is not active Timeout: [1m], request: [BulkShardRequest [[newindexgst][0]] containing [5] requests]解决方法:
将elasticsearch移动到一个大的磁盘空间```java@GetMapping("saveUser")public ArrayList<User> saveUser() {//添加索引mapping索引会自动创建但mapping自只用默认的这会导致分词器不生效 所以这里我们手动导入mappingRandom random = new Random();List<User> users = new ArrayList<>();for (int i = 0; i < 20; i++) {User user = new User();user.setId(i);user.setName(names[random.nextInt(9)]);user.setAge(random.nextInt(40) + i);user.setInfo(infos[random.nextInt(2)]);users.add(user);}ArrayList<User> users1 = (ArrayList<User>) esUserService.saveAll(users);return users1;}

elasticreposity插入会成功,但是返回会失败,这个可以选择放弃

http://www.lryc.cn/news/97154.html

相关文章:

  • SAP安装笔记
  • 速速收藏!程序员副业赚钱的8种模式
  • 2、基于redis实现分布式锁
  • 【问题记录】Ubuntu 22.04 环境下,程序报:段错误(核心已转储)怎么使用 core 文件和GDB调试器 解决?
  • 9 Linux实操篇-实用指令
  • Hbase基础概念
  • JTS-Angle角度类
  • pytest---环境切换(base-url)
  • linux跑代码,程序终止了,但资源没有释放。
  • 数据结构--线性表2-1
  • 网访问内网机器:基于frp的内网穿透
  • 【Spring框架】Spring读取与存储综合练习
  • Python实现指定区域桌面变化监控并报警
  • 【数据结构】实验五:栈
  • ⚡️⚡️Java多线程编程的高效、安全实践
  • 【云原生】Docker私有仓库registry
  • 第十四届蓝桥杯大赛青少年省赛C++组试题真题 2023年5月
  • GAN论文精读
  • 数据结构:计数排序(详解)
  • 1 请使用js、css、html技术实现以下页面,表格内容根据查询条件动态变化。
  • react-native项目安卓版本升级 compileSdkVersion 29->31
  • 【学习笔记】目标跟踪领域SOTA方法比较
  • 机器学习 深度学习编程笔记
  • 18.背景轮播
  • 论文代码学习—HiFi-GAN(2)——鉴别器discriminator代码
  • Linux Shell 脚本编程学习之【第3章 正则表达式 (第二部分) grep命令】
  • 大语言模型LLM
  • 自学网络安全(黑客)的误区
  • @Conditional
  • 【Linux】网络基础之TCP协议