Cluster-health check with elasticsearch-java against 7.x cluster

Getting cluster health from an es-7 cluster using the elasticsearch-java (es8) language client does not work out of the box. How do I configure the client in a compatible way?

We are finishing our migration from es7 clients to the newer elasticsearch-java client for es8.

I would like to return a cluster health response using the elasticsearch-java, es8 client talking to an es7 server cluster using the following code:

@Service
public class OurService {
  //...
  private final ElasticsearchClient client;
 //...

    @Autowired
    public OurService(final @NotNull ElasticsearchClient client) {
      //...
        this.client = client;
    }

    public HealthResponse getHealth() throws IOException {
        return this.client.cluster().health();
    }
//...
}

I configured the client as follows:

//...
  public static @NotNull ElasticsearchClient createElasticsearchClient(
   final @NotNull RestClient restClient,
   final @NotNull JacksonJsonpMapper jacksonJsonpMapper) {
        //final var transport = new RestClientTransport(restClient, jacksonJsonpMapper); //original code
        final TransportOptions  transportOptions = null;//How to configure the TransportOptions?
        final var transport = new RestClientTransport(restClient, jacksonJsonpMapper, transportOptions);
        return new ElasticsearchClient(transport);
    }
//...

How should I configure the TransportOptions?
Here all kinds of AI hallucinate the most beautiful non-existing solutions.

Some human guidance is appreciated here.

Hello!

As a human developer, I'm sorry to say that this is a known incompatibility between version 8 of the java client and version 7 of the server.

Elasticsearch server version 8 has a new required property, unassigned_primary_shards, which we require in the client version 8 as well; consequently, calling cluster health will fail with Missing required property 'HealthResponse.unassignedPrimaryShards'.

As stated in the compatibility section of the readme, the client is forward compatible, so there's no guarantee it will work with older versions of the server.

For some cases there is a workaround consisting in disabling the "required properties" check, but it doesn't work with primitive types, which is the case here - we do have plans to make it work in this situations too.