elasticsearchresthighlevelclientmget

mget producing: Unable to parse response body for Response


I'm issuing a Multi-Get request via the Java High Level REST Client and I'm receiving the following exception:

"Unable to parse response body for Response{requestLine=POST /_mget HTTP/1.1, host=http://localhost:9200, response=HTTP/1.1 200 OK}"

I pulled the following JSON from the logs that was sent to Elastic:

{
    "docs": [
        {
            "_index": "blah",
            "_type": null,
            "_id": "some-id-232332",
            "routing": null,
            "stored_fields": null,
            "version": -3,
            "version_type": "internal",
            "_source": {
                "includes": [],
                "excludes": []
            }
        }
    ]
}

I sent the above JSON to Elastic via Postman and I'm seeing the following response (which is the same I see in the logs):

{
    "docs": [
        {
            "_index": "blah",
            "_type": null,
            "_id": "some-id-232332",
            "found": false
        }
    ]
}

Isn't that a valid response? Is this an issue w/ the elasticsearch-rest-high-level-client?

Elastic 7.5.0, org.elasticsearch.client:elasticsearch-rest-high-level-client:7.5.2


Solution

  • I needed to check the getCause()'s of the exception for the real problem. I was passing null to Jackson on mapper.readValue(nullBytes, Customer.class); was the real problem.

    Interestingly enough a NPE shows itself 🤷‍♂️.

    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);
        }
      });
    

    Full source of repro, Full log file