Skip to content

Cannot set custom retries handler for Elasticsearch RestClient  #1948

@oridool

Description

@oridool

When using httpclient directly, I have the option to set my own retries handler. Example:
https://www.programcreek.com/java-api-examples/?api=org.apache.http.client.HttpRequestRetryHandler

However, when configuring the RestClient with spring-data-elasticseaarch, I only have access to HttpAsyncClientBuilder through TerminalClientConfigurationBuilder#withHttpClientConfigurer, which doesn't allow me to do so (it is probably required that Elasticsearch client would upgrade internal httpclient to 5.x, while now it is using 4.1.4).

I'm also familiar with the ability to override ElasticsearchRestTemplate's execute method :

    private ElasticsearchRestTemplate createElasticsearchRestTemplateForElasticsearchOperations(ElasticsearchConverter elasticsearchConverter, RestHighLevelClient elasticsearchClient) {
        return new ElasticsearchRestTemplate(elasticsearchClient, elasticsearchConverter) {
            @Override
            public <T> T execute(ClientCallback<T> callback) {
                int retryCount = 0;
                T t = null;
                // do some logic
                return t;
            }
        };

But this doesn't help in all cases, because most APIs are not using execute.

Is there any way to configure my own retries strategy/handler?
If not, can it be added as an enhancement ?

Thank you.

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