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。