测试elasticsearch保存时报找不到类型的错误
2024-10-21 15:31:12
java测试存储数据到es时报错:...ActionRequestValidationException: Validation Failed: 1: type is missing...
/**
* 测试存储数据到 es
*/
@Test
public void indexData() throws IOException {
IndexRequest indexRequest = new IndexRequest("users");
indexRequest.id("1"); //数据的id
// indexRequest.source("username","zhangsan","age",18,"gender","男");
User user = new User();
String jsonString = JSON.toJSONString(user);
indexRequest.source(jsonString, XContentType.JSON); //要保存的内容
//执行保存操作
IndexResponse index = client.index(indexRequest, GulimallElasticSearchConfig.COMMON_OPTIONS);
//提取有用的响应数据
System.out.println(index);
}
解决:
尝试导入以下三个依赖:
<!-- 使用elasticsearch导入的三个包 -->
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.1.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.1.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.1.0</version>
</dependency>
有的导入上面三个包了,但还是报错,可以将版本改成7.1.0,或者尝试其他版本试一下。
最新文章
- css中“~”和“>;”是什么意思?
- 代码阅读工具:Source Navigator和Source Insight
- KendoUI系列:Window
- java多线程的等待唤醒机制及如何解决同步过程中的安全问题
- cell分割线宽度不满屏处理
- Working With Taxonomy Field in CSOM
- JavasScript判断输入框不为空
- extjs的combobox的用法
- 浅谈string
- 推荐15个月 Node.js 开发工具
- 【从翻译mos文章】Weblogic AdminServer 启动fail,报错&;quot;unable to get file lock, will retry&;quot;
- HDU 4081 Qin Shi Huang&#39;s National Road System 次小生成树变种
- 使用netflix Zuul 代理你的微服务
- 【一天一道LeetCode】#33. Search in Rotated Sorted Array
- C++学习(三十三)(C语言部分)之 队列
- currentTarget
- Web框架的原理
- 防盗链之URL参数签名 总结
- eclipse插件安装的四种方法
- 虚拟机中安装Ubuntu 16.04
热门文章
- ORACLE 遇到ORA-31693 ORA-31617 ORA-19505 ORA-27037
- Qt5.6使用Qt自带虚拟键盘
- SSL certificate problem: unable to get local issuer certificate 错误解决
- Redis哨兵模式+缓存穿透、击穿和雪崩
- python经典例题
- nodejs查询
- LightOJ - 1162 Min Max Roads
- pytest-2 之前后置及 conftest.py+fixture+yield实现用例前后置
- shell - scriptreplay timing.log output.session
- 日常遇到bug小记