Improve Elasticsearch RestClient customization capabilities #20994
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
At present,
RestClientBuilderCustomizerallows general customization ofRestClientBuilder. This is troublesome for users that want to customizeHttpAsyncClientBuilderandRequestConfig.Buildersince those are set on theRestClientBuilder. By customizing those two builders users lose out on Spring Boot's support for bindingusername,password,connection-timeoutandread-timeoutproperties fromspring.elasticsearch.restnamespace.To illustrate the problem, attempting to customize aspects of
HttpAsyncClientBuilderlike this:Will disable the binding of
usernameandpasswordproperties applied here:spring-boot/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientConfigurations.java
Lines 57 to 62 in 70d4994
To work around this, users need to replicate Spring Boot's configuration logic using something like:
This PR enhances the
RestClientBuilderCustomizerwith support for customizingHttpAsyncClientBuilderandRequestConfig.Builderby providing additional#customizemethods that accept the aforementioned builders. Both new methods are optional as they have no-op default implementations.