Skip to content

Commit

Permalink
ESQL: expose transport action to improve usage (#106463)
Browse files Browse the repository at this point in the history
This commits exposes the query transport action to improve usage. While one can perform all operations prior to this change, it has been suggested that adding the action would improve the symmetry of the API by allowing e.g.

client().execute(builder.action(), builder.request()).actionGet(30, SECONDS);
  • Loading branch information
ChrisHegarty authored Mar 20, 2024
1 parent 6f607e4 commit 32bc182
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
public abstract class EsqlQueryRequestBuilder<Request extends EsqlQueryRequest, Response extends EsqlQueryResponse> extends
ActionRequestBuilder<Request, Response> {

private final ActionType<Response> action;

/** Creates a new ES|QL query request builder. */
public static EsqlQueryRequestBuilder<? extends EsqlQueryRequest, ? extends EsqlQueryResponse> newRequestBuilder(
ElasticsearchClient client
Expand All @@ -26,6 +28,11 @@ public abstract class EsqlQueryRequestBuilder<Request extends EsqlQueryRequest,
// not for direct use
protected EsqlQueryRequestBuilder(ElasticsearchClient client, ActionType<Response> action, Request request) {
super(client, action, request);
this.action = action;
}

public final ActionType<Response> action() {
return action;
}

public abstract EsqlQueryRequestBuilder<Request, Response> query(String query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ public void testAccessAfterClose() {

protected EsqlQueryResponse run(EsqlQueryRequestBuilder<? extends EsqlQueryRequest, ? extends EsqlQueryResponse> request) {
try {
// The variants here ensure API usage patterns
if (randomBoolean()) {
return request.execute().actionGet(30, SECONDS);
} else if (randomBoolean()) {
return client().execute(request.action(), request.request()).actionGet(30, SECONDS);
} else {
return ClientHelper.executeWithHeaders(
Map.of("Foo", "bar"),
Expand Down

0 comments on commit 32bc182

Please sign in to comment.