Skip to content

Spring Boot and Spring Data Elasticsearch

Peter-Josef Meisch edited this page Jul 14, 2019 · 3 revisions

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 (SDE) and Elasticsearch (ES) that are specified in the dependency bom.[1]

  • 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 <elasticsearch.version> 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.

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:

@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:

@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();
	}
}

1. when creating this page, 2.1.6 is the current Spring Boot version, so the whole history is not added to this table