Skip to content

Commit 727cb5e

Browse files
kevinleturcakonczak
authored andcommitted
DATAES-141 - Update ElasticsearchTemplate constructors to init properly the default implementations.
1 parent aa44da6 commit 727cb5e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,34 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
116116
private String searchTimeout;
117117

118118
public ElasticsearchTemplate(Client client) {
119-
this(client, null, null);
119+
this(client, new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext()));
120120
}
121121

122122
public ElasticsearchTemplate(Client client, EntityMapper entityMapper) {
123-
this(client, null, new DefaultResultMapper(entityMapper));
123+
this(client, new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext()), entityMapper);
124+
}
125+
126+
public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearchConverter, EntityMapper entityMapper) {
127+
this(client, elasticsearchConverter, new DefaultResultMapper(elasticsearchConverter.getMappingContext(), entityMapper));
124128
}
125129

126130
public ElasticsearchTemplate(Client client, ResultsMapper resultsMapper) {
127-
this(client, null, resultsMapper);
131+
this(client, new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext()), resultsMapper);
128132
}
129133

130134
public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearchConverter) {
131-
this(client, elasticsearchConverter, null);
135+
this(client, elasticsearchConverter, new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
132136
}
133137

134138
public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearchConverter, ResultsMapper resultsMapper) {
139+
140+
Assert.notNull(client, "Client must not be null!");
141+
Assert.notNull(elasticsearchConverter, "ElasticsearchConverter must not be null!");
142+
Assert.notNull(resultsMapper, "ResultsMapper must not be null!");
143+
135144
this.client = client;
136-
this.elasticsearchConverter = (elasticsearchConverter == null) ? new MappingElasticsearchConverter(
137-
new SimpleElasticsearchMappingContext()) : elasticsearchConverter;
138-
this.resultsMapper = (resultsMapper == null) ? new DefaultResultMapper(this.elasticsearchConverter.getMappingContext()) : resultsMapper;
145+
this.elasticsearchConverter = elasticsearchConverter;
146+
this.resultsMapper = resultsMapper;
139147
}
140148

141149
public void setSearchTimeout(String searchTimeout) {

0 commit comments

Comments
 (0)