mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-12 07:02:10 +00:00
DATES-666 - Rebase 4.0.x onto master and merge.
This commit is contained in:
parent
d3295a6416
commit
d72ee18944
@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||||
import org.springframework.data.elasticsearch.annotations.Mapping;
|
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
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;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,12 +19,6 @@ public abstract class AbstractElasticsearchTemplate {
|
|||||||
|
|
||||||
protected ElasticsearchConverter elasticsearchConverter;
|
protected ElasticsearchConverter elasticsearchConverter;
|
||||||
|
|
||||||
public AbstractElasticsearchTemplate(ElasticsearchConverter elasticsearchConverter) {
|
|
||||||
|
|
||||||
Assert.notNull(elasticsearchConverter, "elasticsearchConverter must not be null.");
|
|
||||||
this.elasticsearchConverter = elasticsearchConverter;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String buildMapping(Class<?> clazz) {
|
protected String buildMapping(Class<?> clazz) {
|
||||||
|
|
||||||
// load mapping specified in Mapping annotation if present
|
// load mapping specified in Mapping annotation if present
|
||||||
|
@ -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.ElasticsearchConverter;
|
||||||
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
||||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
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.ElasticsearchPersistentEntity;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||||
@ -162,8 +161,8 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
|
|||||||
new DefaultResultMapper(mappingElasticsearchConverter.getMappingContext()));
|
new DefaultResultMapper(mappingElasticsearchConverter.getMappingContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElasticsearchRestTemplate(RestHighLevelClient client,
|
public ElasticsearchRestTemplate(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter,
|
||||||
ElasticsearchConverter elasticsearchConverter, EntityMapper entityMapper) {
|
EntityMapper entityMapper) {
|
||||||
initialize(client, elasticsearchConverter,
|
initialize(client, elasticsearchConverter,
|
||||||
new DefaultResultMapper(elasticsearchConverter.getMappingContext(), entityMapper));
|
new DefaultResultMapper(elasticsearchConverter.getMappingContext(), entityMapper));
|
||||||
}
|
}
|
||||||
@ -172,14 +171,12 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
|
|||||||
initialize(client, createElasticsearchConverter(), resultsMapper);
|
initialize(client, createElasticsearchConverter(), resultsMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElasticsearchRestTemplate(RestHighLevelClient client,
|
public ElasticsearchRestTemplate(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter) {
|
||||||
ElasticsearchConverter elasticsearchConverter) {
|
initialize(client, elasticsearchConverter, new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
|
||||||
initialize(client, elasticsearchConverter,
|
|
||||||
new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElasticsearchRestTemplate(RestHighLevelClient client,
|
public ElasticsearchRestTemplate(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter,
|
||||||
ElasticsearchConverter elasticsearchConverter, ResultsMapper resultsMapper) {
|
ResultsMapper resultsMapper) {
|
||||||
initialize(client, elasticsearchConverter, resultsMapper);
|
initialize(client, elasticsearchConverter, resultsMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,9 +187,8 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
|
|||||||
private void initialize(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter,
|
private void initialize(RestHighLevelClient client, ElasticsearchConverter elasticsearchConverter,
|
||||||
ResultsMapper resultsMapper) {
|
ResultsMapper resultsMapper) {
|
||||||
|
|
||||||
super(elasticsearchConverter);
|
|
||||||
|
|
||||||
Assert.notNull(client, "Client must not be null!");
|
Assert.notNull(client, "Client must not be null!");
|
||||||
|
Assert.notNull(elasticsearchConverter, "elasticsearchConverter must not be null.");
|
||||||
Assert.notNull(resultsMapper, "ResultsMapper must not be null!");
|
Assert.notNull(resultsMapper, "ResultsMapper must not be null!");
|
||||||
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
@ -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.ElasticsearchConverter;
|
||||||
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
||||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
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.ElasticsearchPersistentEntity;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||||
@ -128,7 +127,8 @@ import org.springframework.util.StringUtils;
|
|||||||
* @deprecated as of 4.0
|
* @deprecated as of 4.0
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@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
|
private static final Logger QUERY_LOGGER = LoggerFactory
|
||||||
.getLogger("org.springframework.data.elasticsearch.core.QUERY");
|
.getLogger("org.springframework.data.elasticsearch.core.QUERY");
|
||||||
@ -155,8 +155,7 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearchConverter) {
|
public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearchConverter) {
|
||||||
this(client, elasticsearchConverter,
|
this(client, elasticsearchConverter, new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
|
||||||
new DefaultResultMapper(elasticsearchConverter.getMappingContext()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private MappingElasticsearchConverter createElasticsearchConverter() {
|
private MappingElasticsearchConverter createElasticsearchConverter() {
|
||||||
@ -166,17 +165,16 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate impleme
|
|||||||
public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearchConverter,
|
public ElasticsearchTemplate(Client client, ElasticsearchConverter elasticsearchConverter,
|
||||||
ResultsMapper resultsMapper) {
|
ResultsMapper resultsMapper) {
|
||||||
|
|
||||||
super(elasticsearchConverter);
|
|
||||||
|
|
||||||
initialize(client, elasticsearchConverter, resultsMapper);
|
initialize(client, elasticsearchConverter, resultsMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize(Client client, ElasticsearchConverter elasticsearchConverter,
|
private void initialize(Client client, ElasticsearchConverter elasticsearchConverter, ResultsMapper resultsMapper) {
|
||||||
ResultsMapper resultsMapper) {
|
|
||||||
Assert.notNull(client, "Client must not be null!");
|
Assert.notNull(client, "Client must not be null!");
|
||||||
|
Assert.notNull(elasticsearchConverter, "elasticsearchConverter must not be null.");
|
||||||
Assert.notNull(resultsMapper, "ResultsMapper must not be null!");
|
Assert.notNull(resultsMapper, "ResultsMapper must not be null!");
|
||||||
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
this.elasticsearchConverter = elasticsearchConverter;
|
||||||
this.resultsMapper = resultsMapper;
|
this.resultsMapper = resultsMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,10 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
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.annotations.ScriptedField;
|
||||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||||
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
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.geo.GeoPoint;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||||
import org.springframework.data.elasticsearch.core.query.*;
|
import org.springframework.data.elasticsearch.core.query.*;
|
||||||
@ -1667,12 +1672,14 @@ public class ElasticsearchTemplateTests {
|
|||||||
SearchResultMapper searchResultMapper = new SearchResultMapper() {
|
SearchResultMapper searchResultMapper = new SearchResultMapper() {
|
||||||
@Override
|
@Override
|
||||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
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<>();
|
ArrayList<T> result = new ArrayList<>();
|
||||||
|
|
||||||
for (SearchHit searchHit : response.getHits()) {
|
for (SearchHit searchHit : response.getHits()) {
|
||||||
try {
|
try {
|
||||||
result.add((T) defaultEntityMapper.mapToObject(searchHit.getSourceAsString(), SampleEntity.class));
|
result
|
||||||
|
.add((T) mappingElasticsearchConverter.mapToObject(searchHit.getSourceAsString(), SampleEntity.class));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -1688,8 +1695,8 @@ public class ElasticsearchTemplateTests {
|
|||||||
assertThat(highlightFieldMessage.fragments()[0].toString()).isEqualTo(highlightedMessage);
|
assertThat(highlightFieldMessage.fragments()[0].toString()).isEqualTo(highlightedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AggregatedPageImpl<>(result, pageable, response.getHits().getTotalHits(), response.getAggregations(),
|
return new AggregatedPageImpl<T>(result, pageable, response.getHits().getTotalHits().value,
|
||||||
response.getScrollId(), response.getHits().getMaxScore());
|
response.getAggregations(), response.getScrollId(), response.getHits().getMaxScore());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user