在調(diào)用es java客戶端,執(zhí)行新增es文檔時報錯:Unable to parse response body for Response
?
??
返回201,表示插入成功
java.io.IOException: Unable to parse response body for Response{requestLine=PUT /company/_doc/39?timeout=1m HTTP/1.1, host=http://127.0.0.1:31200, response=HTTP/1.1 201 Created}
可以在kibana查詢新增數(shù)據(jù)
?
原因分析:
老版本es客戶端無法解析新版es的返回,有可能是 spring-boot 版本低了,沒有做這方面的處理(數(shù)據(jù)是能保存進 es 的,而且 es 也不報錯)
?
處理:
通過獲取返回體異常信息,判斷處理文章來源:http://www.zghlxwxcb.cn/news/detail-843694.html
/**
* 新增文檔
*
* @param indexName
* @param id
* @param docObj
* @return
*/
public void addDoc(String indexName, String id, Object docObj) {
log.info("es新增文檔,文檔內(nèi)容:{}",docObj);
try {
IndexRequest indexRequest = buildAddDoc(indexName, id, docObj);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
String msg = e.getMessage();
if (!msg.contains("Created")&&!msg.contains("200 OK")){
log.error("es新增文檔失敗,異常信息:", e);
throw new RuntimeException(e);
}
}
}
再次執(zhí)行,正常運行文章來源地址http://www.zghlxwxcb.cn/news/detail-843694.html
到了這里,關(guān)于ES報錯— Unable to parse response body for Response的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!