Skip to content

[BUG]why OpenSearchGenericClient.withTransportOptions(TransportOptions transportOptions) create a new OpenSearchGenericClient object? #1694

@swxEmily

Description

@swxEmily

What is the bug?

A clear and concise description of the bug.
OpenSearchGenericClient.withTransportOptions(TransportOptions transportOptions).execute(Request request) create a new OpenSearchGenericClient in every execution.

How can one reproduce the bug?

Steps to reproduce the behavior.

  1. Create OpenSearchTransport with global connection timeout settings. And create OpenSearchGenericClient.
  2. Most requests use global connection timeout settings to access the server by OpenSearchGenericClient.execute(Request request).
  3. Some special requests need custom connection timeout settings to access the server by OpenSearchGenericClient.withTransportOptions(TransportOptions transportOptions).execute(Request request).

private static void search(OpenSearchGenericClient client, String endPoint, long connectionTimout) {
Request request = Requests.create("GET", endPoint, null, Map.of(), null);
ApacheHttpClient5Options transportOptions = ApacheHttpClient5Options.DEFAULT.toBuilder()
.setRequestConfig(
RequestConfig.custom().setConnectionRequestTimeout(connectionTimout, TimeUnit.SECONDS).build())
.build();
try {
// each request set connectionTimeout independently
Response response = client.withTransportOptions(transportOptions).execute(request);
System.out.println(response);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

What is the expected behavior?

client.withTransportOptions(transportOptions) create a new OpenSearchGenericClient, each request will create a new client object, it will create many temp client objects

What is your host/environment?

linux

Do you have any screenshots?

If applicable, add screenshots to help explain your problem.

Do you have any additional context?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions