Skip to content

Fix Elasticsearch Client API to be less trappy #9201

@s1monw

Description

@s1monw

Today we have 3 flavors for each endpoint (for demonstration purpose I only use the _health API)

public interface ClusterAdminClient extends ElasticsearchClient<ClusterAdminClient> {

    ActionFuture<ClusterHealthResponse> health(ClusterHealthRequest request);

    void health(ClusterHealthRequest request, ActionListener<ClusterHealthResponse> listener);

    ClusterHealthRequestBuilder prepareHealth(String... indices);

At least one of them is redundant here already but lemme first explain what is trappy here. If you use the prepareHealth().setWaitForGreenStatus() basically nothing happens. you need to call .get() or .execute().get() or .actionGet() or any of the X flavors. This is not so much of a problem for health because you are waiting for a response, but for endpoints that don't return info that is generally consumed ie. update settings this has in the past lead to so many test bugs that I consider this evil.

Yet, I think we should remove this method entirely and detach the Builders entirely from the Client. Today once a builder is created like this:

  ClusterHealthRequestBuilder builder = client.prepareHealth().setWaitForGreenStatus()

it's tied to a client and if you close that client the builder can't be executed. To me if we even keep the builder in the future it should only have a build() method that returns the corresponding request. Then you can call:

  ClusterHealthRequestBuilder builder = AdminBuilders.health().setWaitForGreenStatus();
  client.health(builder.build());

which is less trappy... oh wait... client.health(builder.build()); returns an ActionFuture<ClusterHealthResponse> which is also redundant IMO. We already have a non-blocking API using a listener which is equally powerful.

I think what we should move to is this:

public interface ClusterAdminClient extends ElasticsearchClient<ClusterAdminClient> {

    ClusterHealthResponse health(ClusterHealthRequest request);

    void health(ClusterHealthRequest request, ActionListener<ClusterHealthResponse> listener);

that way it's clearly a blocking API and it's easy to use. We still keep the builder (for now ;) ) but remove it's coupling to the client which is super trappy.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions