Bring back Elasticsearch RestClient auto-configuration

Prior to this commit, Spring Boot would only auto-configure the
`RestHighLevelClient` and `RestClientBuilder` if the
`RestHighLevelClient` was present. This was done in 1d73d4ed.

This commit brings back the exposing of the `RestClient` bean in when
exposing the `RestHighLevelClient` or when the `RestHighLevelClient`
is not present. It allows for using the auto-configuration and its
customizers of the `RestClientBuilder` in a similar way as it is done
for the `RestTemplateBuilder` and the `WebClient.Builder`.

The presence of the `elasticsearch-rest-high-level-client` module is
now optional. This opens the door for potentially adding support for
the new Elasticsearch Java Client[1] that is based on the same
`RestClient`.

The health contributor and its configuration has also been updated to
only depend on the low-level RestClient.

See gh-28496

[1] https://github.com/elastic/elasticsearch-java
This commit is contained in:
Filip Hrisafov
2021-11-01 13:30:00 +01:00
committed by Andy Wilkinson
parent e0ae1d3501
commit eb3bf40bdb
13 changed files with 604 additions and 104 deletions

View File

@@ -269,14 +269,14 @@ You can use `spring.elasticsearch.*` properties to further tune how the clients
----
[[data.nosql.elasticsearch.connecting-using-rest.restclient]]
===== Connecting to Elasticsearch using RestHighLevelClient
If you have `elasticsearch-rest-high-level-client` on the classpath, Spring Boot will auto-configure and register a `RestHighLevelClient` bean.
In addition to the properties described previously, to fine-tune the `RestHighLevelClient`, you can register an arbitrary number of beans that implement `RestClientBuilderCustomizer` for more advanced customizations.
===== Connecting to Elasticsearch using RestClient
If you have `elasticsearch-rest-client` on the classpath, Spring Boot will auto-configure and register a `RestClient` bean.
In addition to the properties described previously, to fine-tune the `RestClient`, you can register an arbitrary number of beans that implement `RestClientBuilderCustomizer` for more advanced customizations.
To take full control over its registration, define a `RestClientBuilder` bean.
TIP: If your application needs access to a "Low Level" `RestClient`, you can get it by calling `client.getLowLevelClient()` on the auto-configured `RestHighLevelClient`.
NOTE: If you have `elasticsearch-rest-high-level-client` on the classpath a `RestHighLevelClient` bean will be exposed as well
Additionally, if `elasticsearch-rest-client-sniffer` is on the classpath, a `Sniffer` is auto-configured to automatically discover nodes from a running Elasticsearch cluster and set them on the `RestHighLevelClient` bean.
Additionally, if `elasticsearch-rest-client-sniffer` is on the classpath, a `Sniffer` is auto-configured to automatically discover nodes from a running Elasticsearch cluster and set them on the `RestClient` bean.
You can further tune how `Sniffer` is configured, as shown in the following example:
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]