在调用es java客户端,执行新增es文档时报错:Unable to parse response body for Response
参考:
https://www.zhihu.com/question/631581992/answer/3380627522
原因分析:
老版本es客户端无法解析新版es的返回,有可能是 spring-boot 版本低了,没有做这方面的处理(数据是能保存进 es 的,而且 es 也不报错)
处理方式:
String msg = e.getMessage(); if (!msg.contains("Created")&&!msg.contains("200 OK")){ log.error("es新增文档失败,异常信息:", e); throw new RuntimeException(e); }
可以查询到对应的 新增到ES的记录信息
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7805a3ef]
2024-05-09 14:57:22.805 ERROR 10628 --- [io-51831-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: java.io.IOException: Unable to parse response body for Response{requestLine=PUT /hotel22/_doc/2?timeout=1m HTTP/1.1, host=http://192.168.36.128:9200, response=HTTP/1.1 200 OK}] with root cause
java.lang.NullPointerException: null
at java.util.Objects.requireNonNull(Objects.java:203) ~[na:1.8.0_221]
at org.elasticsearch.action.DocWriteResponse.<init>(DocWriteResponse.java:127) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.action.index.IndexResponse.<init>(IndexResponse.java:50) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsea