Skip to content

Commit d282eb6

Browse files
committed
Upgrade to Elasticsearch 7.5.1
See gh-19588
1 parent f268ede commit d282eb6

File tree

8 files changed

+73
-66
lines changed

8 files changed

+73
-66
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataConfiguration.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,15 +27,11 @@
2727
import org.springframework.context.annotation.Bean;
2828
import org.springframework.context.annotation.Configuration;
2929
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
30-
import org.springframework.data.elasticsearch.core.DefaultEntityMapper;
31-
import org.springframework.data.elasticsearch.core.DefaultResultMapper;
3230
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
3331
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
3432
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
35-
import org.springframework.data.elasticsearch.core.EntityMapper;
3633
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
3734
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
38-
import org.springframework.data.elasticsearch.core.ResultsMapper;
3935
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
4036
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
4137
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
@@ -48,6 +44,7 @@
4844
* their order of execution.
4945
*
5046
* @author Brian Clozel
47+
* @author Scott Frederick
5148
*/
5249
abstract class ElasticsearchDataConfiguration {
5350

@@ -66,18 +63,6 @@ SimpleElasticsearchMappingContext mappingContext() {
6663
return new SimpleElasticsearchMappingContext();
6764
}
6865

69-
@Bean
70-
@ConditionalOnMissingBean
71-
EntityMapper entityMapper(SimpleElasticsearchMappingContext mappingContext) {
72-
return new DefaultEntityMapper(mappingContext);
73-
}
74-
75-
@Bean
76-
@ConditionalOnMissingBean
77-
ResultsMapper resultsMapper(SimpleElasticsearchMappingContext mappingContext, EntityMapper entityMapper) {
78-
return new DefaultResultMapper(mappingContext, entityMapper);
79-
}
80-
8166
}
8267

8368
@Configuration(proxyBeanMethods = false)
@@ -87,9 +72,8 @@ static class RestClientConfiguration {
8772
@Bean
8873
@ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate")
8974
@ConditionalOnBean(RestHighLevelClient.class)
90-
ElasticsearchRestTemplate elasticsearchTemplate(RestHighLevelClient client, ElasticsearchConverter converter,
91-
ResultsMapper resultsMapper) {
92-
return new ElasticsearchRestTemplate(client, converter, resultsMapper);
75+
ElasticsearchRestTemplate elasticsearchTemplate(RestHighLevelClient client, ElasticsearchConverter converter) {
76+
return new ElasticsearchRestTemplate(client, converter);
9377
}
9478

9579
}
@@ -101,10 +85,10 @@ static class TransportClientConfiguration {
10185
@Bean
10286
@ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate")
10387
@ConditionalOnBean(Client.class)
104-
ElasticsearchTemplate elasticsearchTemplate(Client client, ElasticsearchConverter converter,
105-
ResultsMapper resultsMapper) {
88+
@Deprecated
89+
ElasticsearchTemplate elasticsearchTemplate(Client client, ElasticsearchConverter converter) {
10690
try {
107-
return new ElasticsearchTemplate(client, converter, resultsMapper);
91+
return new ElasticsearchTemplate(client, converter);
10892
}
10993
catch (Exception ex) {
11094
throw new IllegalStateException(ex);
@@ -121,9 +105,8 @@ static class ReactiveRestClientConfiguration {
121105
@ConditionalOnMissingBean(value = ReactiveElasticsearchOperations.class, name = "reactiveElasticsearchTemplate")
122106
@ConditionalOnBean(ReactiveElasticsearchClient.class)
123107
ReactiveElasticsearchTemplate reactiveElasticsearchTemplate(ReactiveElasticsearchClient client,
124-
ElasticsearchConverter converter, ResultsMapper resultsMapper) {
125-
ReactiveElasticsearchTemplate template = new ReactiveElasticsearchTemplate(client, converter,
126-
resultsMapper);
108+
ElasticsearchConverter converter) {
109+
ReactiveElasticsearchTemplate template = new ReactiveElasticsearchTemplate(client, converter);
127110
template.setIndicesOptions(IndicesOptions.strictExpandOpenAndForbidClosed());
128111
template.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
129112
return template;

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfigurationTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,8 +47,8 @@
4747
class ElasticsearchAutoConfigurationTests {
4848

4949
@Container
50-
public static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5)
51-
.withStartupTimeout(Duration.ofMinutes(10));
50+
public static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer()
51+
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
5252

5353
private AnnotationConfigApplicationContext context;
5454

@@ -76,6 +76,7 @@ void useExistingClient() {
7676
}
7777

7878
@Test
79+
@SuppressWarnings("deprecation")
7980
void createTransportClient() {
8081
this.context = new AnnotationConfigApplicationContext();
8182
TestPropertyValues

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchDataAutoConfigurationTests.java

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,10 +30,8 @@
3030
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
3131
import org.springframework.context.annotation.Bean;
3232
import org.springframework.context.annotation.Configuration;
33-
import org.springframework.data.elasticsearch.core.ElasticsearchEntityMapper;
3433
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
3534
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
36-
import org.springframework.data.elasticsearch.core.EntityMapper;
3735
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
3836
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
3937
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
@@ -48,12 +46,13 @@
4846
* @author Artur Konczak
4947
* @author Brian Clozel
5048
* @author Peter-Josef Meisch
49+
* @author Scott Frederick
5150
*/
5251
@Testcontainers(disabledWithoutDocker = true)
5352
class ElasticsearchDataAutoConfigurationTests {
5453

5554
@Container
56-
static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5)
55+
static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5)
5756
.withStartupTimeout(Duration.ofMinutes(10));
5857

5958
private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
@@ -71,6 +70,7 @@ void tearDown() {
7170
}
7271

7372
@Test
73+
@SuppressWarnings("deprecation")
7474
void defaultTransportBeansAreRegistered() {
7575
this.contextRunner
7676
.withPropertyValues(
@@ -83,6 +83,7 @@ void defaultTransportBeansAreRegistered() {
8383
}
8484

8585
@Test
86+
@SuppressWarnings("deprecation")
8687
void defaultTransportBeansNotRegisteredIfNoTransportClient() {
8788
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(ElasticsearchTemplate.class));
8889
}
@@ -91,16 +92,11 @@ void defaultTransportBeansNotRegisteredIfNoTransportClient() {
9192
void defaultRestBeansRegistered() {
9293
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(ElasticsearchRestTemplate.class)
9394
.hasSingleBean(ReactiveElasticsearchTemplate.class).hasSingleBean(ElasticsearchConverter.class)
94-
.hasSingleBean(SimpleElasticsearchMappingContext.class).hasSingleBean(EntityMapper.class)
9595
.hasSingleBean(ElasticsearchConverter.class));
9696
}
9797

9898
@Test
99-
void defaultEntityMapperRegistered() {
100-
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(EntityMapper.class));
101-
}
102-
103-
@Test
99+
@SuppressWarnings("deprecation")
104100
void customTransportTemplateShouldBeUsed() {
105101
this.contextRunner.withUserConfiguration(CustomTransportTemplate.class).run((context) -> assertThat(context)
106102
.getBeanNames(ElasticsearchTemplate.class).hasSize(1).contains("elasticsearchTemplate"));
@@ -119,16 +115,11 @@ void customReactiveRestTemplateShouldBeUsed() {
119115
.contains("reactiveElasticsearchTemplate"));
120116
}
121117

122-
@Test
123-
void customEntityMapperShouldeBeUsed() {
124-
this.contextRunner.withUserConfiguration(CustomEntityMapper.class).run((context) -> assertThat(context)
125-
.getBeanNames(EntityMapper.class).containsExactly("elasticsearchEntityMapper"));
126-
}
127-
128118
@Configuration(proxyBeanMethods = false)
129119
static class CustomTransportTemplate {
130120

131121
@Bean
122+
@SuppressWarnings("deprecation")
132123
ElasticsearchTemplate elasticsearchTemplate() {
133124
return mock(ElasticsearchTemplate.class);
134125
}
@@ -155,14 +146,4 @@ ReactiveElasticsearchTemplate reactiveElasticsearchTemplate() {
155146

156147
}
157148

158-
@Configuration(proxyBeanMethods = false)
159-
static class CustomEntityMapper {
160-
161-
@Bean
162-
EntityMapper elasticsearchEntityMapper() {
163-
return mock(ElasticsearchEntityMapper.class);
164-
}
165-
166-
}
167-
168149
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesAutoConfigurationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,8 +48,8 @@
4848
class ElasticsearchRepositoriesAutoConfigurationTests {
4949

5050
@Container
51-
static final ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5)
52-
.withStartupTimeout(Duration.ofMinutes(10));
51+
static final ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer()
52+
.withStartupAttempts(5).withStartupTimeout(Duration.ofMinutes(10));
5353

5454
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
5555
.withConfiguration(

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveElasticsearchRepositoriesAutoConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@
4747
public class ReactiveElasticsearchRepositoriesAutoConfigurationTests {
4848

4949
@Container
50-
static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5)
50+
static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5)
5151
.withStartupTimeout(Duration.ofMinutes(10));
5252

5353
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfigurationTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@
4747
public class ReactiveRestClientAutoConfigurationTests {
4848

4949
@Container
50-
static ElasticsearchContainer elasticsearch = new ElasticsearchContainer().withStartupAttempts(5)
50+
static ElasticsearchContainer elasticsearch = new VersionOverridingElasticsearchContainer().withStartupAttempts(5)
5151
.withStartupTimeout(Duration.ofMinutes(10));
5252

5353
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
@@ -83,9 +83,10 @@ void restClientCanQueryElasticsearchNode() {
8383
Map<String, String> source = new HashMap<>();
8484
source.put("a", "alpha");
8585
source.put("b", "bravo");
86-
IndexRequest index = new IndexRequest("foo", "bar", "1").source(source);
87-
GetRequest getRequest = new GetRequest("foo", "bar", "1");
88-
GetResult getResult = client.index(index).then(client.get(getRequest)).block();
86+
IndexRequest indexRequest = new IndexRequest("foo").id("1").source(source);
87+
GetRequest getRequest = new GetRequest("foo").id("1");
88+
GetResult getResult = client.index(indexRequest).then(client.get(getRequest)).block();
89+
assertThat(getResult).isNotNull();
8990
assertThat(getResult.isExists()).isTrue();
9091
});
9192
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.boot.autoconfigure.data.elasticsearch;
17+
18+
import org.testcontainers.elasticsearch.ElasticsearchContainer;
19+
20+
/**
21+
* Extension of {@link ElasticsearchContainer} to override default version.
22+
*
23+
* @author Scott Frederick
24+
*/
25+
public class VersionOverridingElasticsearchContainer extends ElasticsearchContainer {
26+
27+
/**
28+
* Elasticsearch Docker base URL
29+
*/
30+
private static final String ELASTICSEARCH_IMAGE = "docker.elastic.co/elasticsearch/elasticsearch";
31+
32+
/**
33+
* Elasticsearch version
34+
*/
35+
protected static final String ELASTICSEARCH_VERSION = "7.5.1";
36+
37+
public VersionOverridingElasticsearchContainer() {
38+
super(ELASTICSEARCH_IMAGE + ":" + ELASTICSEARCH_VERSION);
39+
}
40+
41+
}

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ bom {
288288
]
289289
}
290290
}
291-
library('Elasticsearch', '6.8.5') {
291+
library('Elasticsearch', '7.5.1') {
292292
group('org.elasticsearch') {
293293
modules = [
294294
'elasticsearch'

0 commit comments

Comments
 (0)