mget producing:无法解析响应的响应主体
mget producing: Unable to parse response body for Response
我正在通过 Java 高级 REST 客户端发出 Multi-Get request,我收到以下异常:
"Unable to parse response body for Response{requestLine=POST /_mget HTTP/1.1, host=http://localhost:9200, response=HTTP/1.1 200 OK}"
我从发送到 Elastic 的日志中提取了以下 JSON:
{
"docs": [
{
"_index": "blah",
"_type": null,
"_id": "some-id-232332",
"routing": null,
"stored_fields": null,
"version": -3,
"version_type": "internal",
"_source": {
"includes": [],
"excludes": []
}
}
]
}
我通过 Postman 将上述 JSON 发送到 Elastic,我看到了以下响应(与我在日志中看到的相同):
{
"docs": [
{
"_index": "blah",
"_type": null,
"_id": "some-id-232332",
"found": false
}
]
}
这不是一个有效的回应吗?这是 elasticsearch-rest-high-level-client 的问题吗?
弹性 7.5.0,org.elasticsearch.client:elasticsearch-rest-high-level-client:7.5.2
我需要检查异常的 getCause()
以了解真正的问题。我在 mapper.readValue(nullBytes, Customer.class);
上将 null
传递给 Jackson 才是真正的问题。
Stack trace:
java.util.concurrent.ExecutionException: java.io.IOException: Unable to parse response body for Response{requestLine=POST /_mget HTTP/1.1, host=http://localhost:9200, response=HTTP/1.1 200 OK}
...
...
THE REAL PROBLEM IS HERE!!!
Caused by: java.lang.IllegalArgumentException: argument "src" is null
at com.fasterxml.jackson.databind.ObjectMapper._assertNotNull(ObjectMapper.java:4429)
restHighLevelClient.mgetAsync(multiGetRequest, RequestOptions.DEFAULT, new ActionListener<MultiGetResponse>() {
@Override
public void onResponse(MultiGetResponse response) {
for (var responseItem : response.getResponses()) {
try {
// simulating a null source
byte[] nullBytes = null;
customer = mapper.readValue(nullBytes, Customer.class);
} catch (IOException e) {
result.completeExceptionally(e);
}
}
result.complete(true);
}
@Override
public void onFailure(Exception ex) {
//the real problem!!!
//log.error("ex.cause", ex.getCause());
log.error("error with mget", ex);
result.completeExceptionally(ex);
}
});
我正在通过 Java 高级 REST 客户端发出 Multi-Get request,我收到以下异常:
"Unable to parse response body for Response{requestLine=POST /_mget HTTP/1.1, host=http://localhost:9200, response=HTTP/1.1 200 OK}"
我从发送到 Elastic 的日志中提取了以下 JSON:
{
"docs": [
{
"_index": "blah",
"_type": null,
"_id": "some-id-232332",
"routing": null,
"stored_fields": null,
"version": -3,
"version_type": "internal",
"_source": {
"includes": [],
"excludes": []
}
}
]
}
我通过 Postman 将上述 JSON 发送到 Elastic,我看到了以下响应(与我在日志中看到的相同):
{
"docs": [
{
"_index": "blah",
"_type": null,
"_id": "some-id-232332",
"found": false
}
]
}
这不是一个有效的回应吗?这是 elasticsearch-rest-high-level-client 的问题吗?
弹性 7.5.0,org.elasticsearch.client:elasticsearch-rest-high-level-client:7.5.2
我需要检查异常的 getCause()
以了解真正的问题。我在 mapper.readValue(nullBytes, Customer.class);
上将 null
传递给 Jackson 才是真正的问题。
Stack trace: java.util.concurrent.ExecutionException: java.io.IOException: Unable to parse response body for Response{requestLine=POST /_mget HTTP/1.1, host=http://localhost:9200, response=HTTP/1.1 200 OK}
...
...
THE REAL PROBLEM IS HERE!!!
Caused by: java.lang.IllegalArgumentException: argument "src" is null at com.fasterxml.jackson.databind.ObjectMapper._assertNotNull(ObjectMapper.java:4429)
restHighLevelClient.mgetAsync(multiGetRequest, RequestOptions.DEFAULT, new ActionListener<MultiGetResponse>() {
@Override
public void onResponse(MultiGetResponse response) {
for (var responseItem : response.getResponses()) {
try {
// simulating a null source
byte[] nullBytes = null;
customer = mapper.readValue(nullBytes, Customer.class);
} catch (IOException e) {
result.completeExceptionally(e);
}
}
result.complete(true);
}
@Override
public void onFailure(Exception ex) {
//the real problem!!!
//log.error("ex.cause", ex.getCause());
log.error("error with mget", ex);
result.completeExceptionally(ex);
}
});