From 2caf14ce99652ba0d2b987ec3ec8bba41260761f Mon Sep 17 00:00:00 2001 From: Peter-Josef Meisch Date: Sun, 14 Jul 2019 13:54:34 +0200 Subject: [PATCH] Updated Spring Boot and Spring Data Elasticsearch (asciidoc) --- ...oot-and-Spring-Data-Elasticsearch.asciidoc | 76 +++++++++++++++++-- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/Spring-Boot-and-Spring-Data-Elasticsearch.asciidoc b/Spring-Boot-and-Spring-Data-Elasticsearch.asciidoc index ec3a8b2..1efb99e 100644 --- a/Spring-Boot-and-Spring-Data-Elasticsearch.asciidoc +++ b/Spring-Boot-and-Spring-Data-Elasticsearch.asciidoc @@ -1,10 +1,76 @@ - Spring Boot defines in it's dependency bom the versions of the different libraries that are supported in the respective Spring Boot version. It specifies a version for Spring Data Elasticsearch and one for Elasticsearch as well. == Versions -The following table lists the versions of Spring Data Elasticsearch and Elasticsearch that are specified in the dependency bom +The following table lists the versions of Spring Data Elasticsearch (SDE) and Elasticsearch (ES) that are specified in the dependency bom.footnote:[when creating this page, 2.1.6 is the current Spring Boot version, so the whole history is not added to this table] + +* *SB*: Spring Boot version +* *SB-ES*: Elasticsearch version defined in the Spring Boot dependency bom +* *SDE*: Spring Data Elasticsearch version defined in the Spring Boot dependency bom +* *SDE-ES*: Elasticsearch version used by the given SDE version + +The predefined version of Elasticsearch can be overwritten in your pom by setting the `` properties. + +NOTE: defining a different version for Elasticsearch client libraries can lead to errors in the interaction of Spring Data Elasticsearch with the Elasticsearch client lib or in the communication with the Elasticsearch cluster. + |=== -| Spring Boot | Spring Data Elasticsearch | Elasticsearch | -| 2.1.4.RELEASE | Lovelace-SR6 | 6.4.3 | -|=== \ No newline at end of file +| SB | SB-ES | SDE | SDE-ES +| 2.1.6.RELEASE | 6.4.3 | Lovelace-SR9 / 3.1.9.RELEASE | 6.2.2 +| 2.1.5.RELEASE | 6.4.3 | Lovelace-SR8 / 3.1.8.RELEASE | 6.2.2 +| 2.1.4.RELEASE | 6.4.3 | Lovelace-SR6 / 3.1.6.RELEASE | 6.2.2 +|=== + +== Workaround for some problems + +=== Running Spring Data Elasticsearch 3.2.0.RC1 with Spring Boot 2.1.6.RELEASE and Actuator. + +To set up the connection to the Elasticsearch cluster with the Java configuration a configuration bean is used: + +[source,java] +---- +@Configuration +public class RestClientConfig extends AbstractElasticsearchConfiguration { + + @Override + @Bean + public RestHighLevelClient elasticsearchClient() { + + final ClientConfiguration clientConfiguration = ClientConfiguration.builder() + .connectedTo("someHost:443") // + .usingSsl() // + .withBasicAuth("elastic", "somePassword") // + .build(); + + return RestClients.create(clientConfiguration).rest(); + } +} + +---- + +When Spring Boot starts up the actuator and this finds the Elasticsearch clients in the classpath, it checks for the existence of a `RestClient` bean (this is the low level rest client from Elasticsearch). This is not found, so a new `RestClient` is created, that tries to connect to _localhost_. To provide the actuator with correct bean, it is necessary to add the bean to the configuration: + +[source,java] +---- +@Configuration +public class RestClientConfig extends AbstractElasticsearchConfiguration { + + // needed for actuator + @Bean + public RestClient restClient(RestHighLevelClient client) { + return client.getLowLevelClient(); + } + + @Override + @Bean + public RestHighLevelClient elasticsearchClient() { + + final ClientConfiguration clientConfiguration = ClientConfiguration.builder() + .connectedTo("someHost:443") // + .usingSsl() // + .withBasicAuth("elastic", "somePassword") // + .build(); + + return RestClients.create(clientConfiguration).rest(); + } +} +----