Missing required property on Elastic Cluster Health check

Very similar to Error: using Java API calling ElasticsearchClient method healthReport()

Updating the Java client (from 8.15.3) to elasticsearch-java:8.16.1 and calling...

HealthResponse healthModel = getEsClient().cluster().health();

throws...

co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'HealthResponse.unassignedPrimaryShards'

The Elasticsearch instance is old 7.x version (but still supported)

Hello! You can refer to this github issue which describes the same problem, and use the proposed workaround. To summarize, yes 7.x is still supported, but the java client is forward compatible, not backward (as the readme states); this is because the server might add/remove parameters, and newer versions of the client will always match the current server version.

Thank you for the link - I tried setting ApiTypeHelper.DANGEROUS_disableRequiredPropertiesCheck(true), but now get:

java.lang.NullPointerException: Cannot invoke "java.lang.Integer.intValue()" because the return value of "co.elastic.clients.util.ApiTypeHelper.requireNonNull(Object, Object, String)" is null

I guess if the property is missing then the value is null. Perhaps there is another DANGEROUS_... option?

Ah that's unfortunate, it's the same case as in the issue, and the workaround doesn't work. The solution here is either to update the server version, or to use the low level rest client to perform the call, which will bypass any form of validation and just return pure json:

Response health = restClient.performRequest(new Request("GET", "/_cluster/health"));
String jsonResponse = new String(health.getEntity().getContent().readAllBytes(), UTF_8);

Thank you. I'll figure something out; probably a low level rest call.