Unable to parse response body for Response{requestLine=PUT

1 异常信息:

复制代码
Caused by: java.lang.RuntimeException: Unable to parse response body for Response{requestLine=PUT /an_path_statistic_log/_doc/11?timeout=1m HTTP/1.1, host=http://192.168.3.60:9200, response=HTTP/1.1 200 OK}
	at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.translateException(ElasticsearchRestTemplate.java:425)
	... 103 common frames omitted
Caused by: java.io.IOException: Unable to parse response body for Response{requestLine=PUT /an_path_statistic_log/_doc/11?timeout=1m HTTP/1.1, host=http://192.168.3.60:9200, response=HTTP/1.1 200 OK}
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1751)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1702)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1672)
	at org.elasticsearch.client.RestHighLevelClient.index(RestHighLevelClient.java:1029)
	at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.lambda$doIndex$0(ElasticsearchRestTemplate.java:158)
	at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.execute(ElasticsearchRestTemplate.java:408)
	... 102 common frames omitted
Caused by: java.lang.NullPointerException: null
	at java.util.Objects.requireNonNull(Objects.java:203)
	at org.elasticsearch.action.DocWriteResponse.<init>(DocWriteResponse.java:116)
	at org.elasticsearch.action.index.IndexResponse.<init>(IndexResponse.java:43)
	at org.elasticsearch.action.index.IndexResponse.<init>(IndexResponse.java:28)
	at org.elasticsearch.action.index.IndexResponse$Builder.build(IndexResponse.java:96)
	at org.elasticsearch.action.index.IndexResponse.fromXContent(IndexResponse.java:78)
	at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:2011)
	at org.elasticsearch.client.RestHighLevelClient.lambda$performRequestAndParseEntity$8(RestHighLevelClient.java:1673)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1749)
	... 107 common frames omitted

2 异常来源:

本异常是博主测试SpringBoot2.6.3集成由Spring开发的Elasticsearch客户端框架Spring Data Elasticsearch4.3.1出现的。

Elasticsearch服务端版本是8.13.4(博客写时最新服务版本),异常内容可知是Elasticsearch服务端返回的格式,客户端无法解析。

找了官网知道是版本不适配。

看其他博主的情况是SpringBoot2 + Elasticsearch服务端7+ 不报异常。

我自己测试可以的版本是SpringBoot3.3.0+Elasticsearch服务端8.13.4 不报异常。

因此解决方案

1.降低Elasticsearch服务端版本,从8+降低到7+

2.升级SpringBoot版本到3+

3.捕获异常。

查看Kibana是能查到插入的数据的,毕竟是响应体无法解析的异常,不影响插入嘛。因此捕获异常也ok。

相关推荐
苏渡苇2 小时前
Spring Insight 里如何把 Span 画成瀑布时间线
后端·spring·spring cloud·springboot·监控·apm
Elasticsearch4 小时前
没有小到无法记录的日志文件:Elastic Agent 如何跟踪低于 1 KiB 阈值的文件
elasticsearch
好菇娘の当自强8 小时前
【Spring Boot 2.x 与 3.x YAML 配置区别详解】
springboot
cnkeysky8 小时前
SpringBoot 整合 nacos 配置中心
nacos·springboot
Elasticsearch8 小时前
使用 Elasticsearch 和 Jina 进行 AI 视频搜索:精准找到你需要的视频片段秒数
elasticsearch
她说..8 小时前
常见设计模式-模板方法模式
java·spring·设计模式·springboot
Hrain-AI17 小时前
AI 爬虫三档授权工程落地:搜索放行、训练拦截、Agent 分层(附脚本)
人工智能·elasticsearch·milvus
智搜广告19 小时前
智搜广告:科技行业AI回答优化公司如何破局
大数据·python·elasticsearch·geo
jonyleek1 天前
企业文档私有化实践:基于JVS数字底座的可控协同架构设计与落地要点
elasticsearch·私有化部署·springcloud·微服务架构·信创适配·jvs·企业文档
小蒜学长1 天前
大学生健康饮食的智慧管理系统(代码+数据库+LW)
java·后端·springboot·大学生·健康饮食