DATES-666 - Rebase 4.0.x onto master and merge.

This commit is contained in:
Peter-Josef Meisch 2019-10-01 20:49:00 +02:00
parent d3295a6416
commit d72ee18944
4 changed files with 26 additions and 31 deletions

View File

@ -5,12 +5,12 @@ import org.slf4j.LoggerFactory;
import org.springframework.data.elasticsearch.ElasticsearchException;
import org.springframework.data.elasticsearch.annotations.Mapping;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.util.Assert;
import org.springframework.data.elasticsearch.core.index.MappingBuilder;
import org.springframework.util.StringUtils;
/**
* AbstractElasticsearchTemplate
*
*
* @author Sascha Woo
*/
public abstract class AbstractElasticsearchTemplate {
@ -19,12 +19,6 @@ public abstract class AbstractElasticsearchTemplate {
protected ElasticsearchConverter elasticsearchConverter;
public AbstractElasticsearchTemplate(ElasticsearchConverter elasticsearchConverter) {
Assert.notNull(elasticsearchConverter, "elasticsearchConverter must not be null.");
this.elasticsearchConverter = elasticsearchConverter;
}
protected String buildMapping(Class<?> clazz) {
// load mapping specified in Mapping annotation if present

View File

@ -101,7 +101,6 @@ import org.springframework.data.elasticsearch.core.client.support.AliasData;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
import org.springframework.data.elasticsearch.core.index.MappingBuilder;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
@ -162,8 +161,8 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
new DefaultResultMapper(mappingElasticsearchConverter.getMappingContext()));
}
public ElasticsearchRestTemplate(RestHighLevelClient client,
ElasticsearchConverter elasticsearchConverter, EntityMapper entityMapper) {
public ElasticsearchRestTemplate(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter,
EntityMapper entityMapper) {
initialize(client, elasticsearchConverter,
new DefaultResultMapper(elasticsearchConverter.getMappingContext(), entityMapper));
}
@ -172,14 +171,12 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
initialize(client, createElasticsearchConverter(), resultsMapper);
}
public ElasticsearchRestTemplate(RestHighLevelClient client,
ElasticsearchConverter elasticsearchConverter) {
initialize(client, elasticsearchConverter,
new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
public ElasticsearchRestTemplate(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter) {
initialize(client, elasticsearchConverter, new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
}
public ElasticsearchRestTemplate(RestHighLevelClient client,
ElasticsearchConverter elasticsearchConverter, ResultsMapper resultsMapper) {
public ElasticsearchRestTemplate(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter,
ResultsMapper resultsMapper) {
initialize(client, elasticsearchConverter, resultsMapper);
}
@ -190,9 +187,8 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
private void initialize(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter,
ResultsMapper resultsMapper) {
super(elasticsearchConverter);
Assert.notNull(client, "Client must not be null!");
Assert.notNull(elasticsearchConverter, "elasticsearchConverter must not be null.");
Assert.notNull(resultsMapper, "ResultsMapper must not be null!");
this.client = client;

View File

@ -88,7 +88,6 @@ import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
import org.springframework.data.elasticsearch.core.index.MappingBuilder;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
@ -128,7 +127,8 @@ import org.springframework.util.StringUtils;
* @deprecated as of 4.0
*/
@Deprecated
public class ElasticsearchTemplate extends AbstractElasticsearchTemplate implements ElasticsearchOperations, EsClient<Client>, ApplicationContextAware {
public class ElasticsearchTemplate extends AbstractElasticsearchTemplate
implements ElasticsearchOperations, EsClient<Client>, ApplicationContextAware {
private static final Logger QUERY_LOGGER = LoggerFactory
.getLogger("org.springframework.data.elasticsearch.core.QUERY");
@ -155,8 +155,7 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate impleme
}
public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearchConverter) {
this(client, elasticsearchConverter,
new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
this(client, elasticsearchConverter, new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
}
private MappingElasticsearchConverter createElasticsearchConverter() {
@ -166,17 +165,16 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate impleme
public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearchConverter,
ResultsMapper resultsMapper) {
super(elasticsearchConverter);
initialize(client, elasticsearchConverter, resultsMapper);
}
private void initialize(Client client, ElasticsearchConverter elasticsearchConverter,
ResultsMapper resultsMapper) {
private void initialize(Client client, ElasticsearchConverter elasticsearchConverter, ResultsMapper resultsMapper) {
Assert.notNull(client, "Client must not be null!");
Assert.notNull(elasticsearchConverter, "elasticsearchConverter must not be null.");
Assert.notNull(resultsMapper, "ResultsMapper must not be null!");
this.client = client;
this.elasticsearchConverter = elasticsearchConverter;
this.resultsMapper = resultsMapper;
}

View File

@ -28,6 +28,10 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.io.IOException;
import java.lang.Double;
import java.lang.Integer;
import java.lang.Long;
import java.lang.Object;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -80,6 +84,7 @@ import org.springframework.data.elasticsearch.annotations.Score;
import org.springframework.data.elasticsearch.annotations.ScriptedField;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
import org.springframework.data.elasticsearch.core.query.*;
@ -1667,12 +1672,14 @@ public class ElasticsearchTemplateTests {
SearchResultMapper searchResultMapper = new SearchResultMapper() {
@Override
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
DefaultEntityMapper defaultEntityMapper = new DefaultEntityMapper(new SimpleElasticsearchMappingContext());
MappingElasticsearchConverter mappingElasticsearchConverter = new MappingElasticsearchConverter(
new SimpleElasticsearchMappingContext());
ArrayList<T> result = new ArrayList<>();
for (SearchHit searchHit : response.getHits()) {
try {
result.add((T) defaultEntityMapper.mapToObject(searchHit.getSourceAsString(), SampleEntity.class));
result
.add((T) mappingElasticsearchConverter.mapToObject(searchHit.getSourceAsString(), SampleEntity.class));
} catch (IOException e) {
e.printStackTrace();
}
@ -1688,8 +1695,8 @@ public class ElasticsearchTemplateTests {
assertThat(highlightFieldMessage.fragments()[0].toString()).isEqualTo(highlightedMessage);
}
return new AggregatedPageImpl<>(result, pageable, response.getHits().getTotalHits(), response.getAggregations(),
response.getScrollId(), response.getHits().getMaxScore());
return new AggregatedPageImpl<T>(result, pageable, response.getHits().getTotalHits().value,
response.getAggregations(), response.getScrollId(), response.getHits().getMaxScore());
}
@Override