2

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

spottedmahn
  • 14,823
  • 13
  • 108
  • 178
  • Could you add more details like your request, or what you asking for? – AMA Mar 05 '20 at 09:04
  • can you provide ur search query, mapping and sample docs in JSON, your rest-client java code, so that we can reproduce the issue and help you – Amit Mar 05 '20 at 09:55
  • Hi @OpsterElasticsearchNinja - I was hoping to avoid creating a simplified sample as posting our code has tons of things that don't apply. I've managed to track it down though. And I've created a sample, please see my answer. – spottedmahn Mar 06 '20 at 15:30
  • 1
    @spottedmahn, will go through it, thanks for following up on this – Amit Mar 06 '20 at 20:29

1 Answers1

4

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

spottedmahn
  • 14,823
  • 13
  • 108
  • 178