升级spring-data-elasticsearch到4.1.3
This commit is contained in:
@@ -47,7 +47,7 @@
|
||||
<spring-social-security.version>1.1.6.RELEASE</spring-social-security.version>
|
||||
<commons-io.version>2.6</commons-io.version>
|
||||
<servlet-api.version>4.0.1</servlet-api.version>
|
||||
<spring-data-elasticsearch.version>3.2.10.RELEASE</spring-data-elasticsearch.version>
|
||||
<spring-data-elasticsearch.version>4.1.3</spring-data-elasticsearch.version>
|
||||
<elasticsearch.version>7.10.2</elasticsearch.version>
|
||||
<knife4j.version>2.0.5</knife4j.version>
|
||||
<hibernate-validator.version>6.2.0.Final</hibernate-validator.version>
|
||||
|
||||
+8
-8
@@ -8,6 +8,7 @@ import com.central.common.utils.JsonUtil;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||
import org.elasticsearch.client.indices.CreateIndexResponse;
|
||||
import org.elasticsearch.client.indices.GetIndexRequest;
|
||||
@@ -21,7 +22,6 @@ import org.elasticsearch.cluster.metadata.AliasMetadata;
|
||||
import org.elasticsearch.cluster.metadata.MappingMetadata;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -40,10 +40,10 @@ import java.util.*;
|
||||
public class IndexServiceImpl implements IIndexService {
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
private final ElasticsearchRestTemplate elasticsearchRestTemplate;
|
||||
private final RestHighLevelClient client;
|
||||
|
||||
public IndexServiceImpl(ElasticsearchRestTemplate elasticsearchRestTemplate) {
|
||||
this.elasticsearchRestTemplate = elasticsearchRestTemplate;
|
||||
public IndexServiceImpl(RestHighLevelClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,7 +57,7 @@ public class IndexServiceImpl implements IIndexService {
|
||||
//mappings
|
||||
request.mapping(indexDto.getMappingsSource(), XContentType.JSON);
|
||||
}
|
||||
CreateIndexResponse response = elasticsearchRestTemplate.getClient()
|
||||
CreateIndexResponse response = client
|
||||
.indices()
|
||||
.create(request, RequestOptions.DEFAULT);
|
||||
return response.isAcknowledged();
|
||||
@@ -66,7 +66,7 @@ public class IndexServiceImpl implements IIndexService {
|
||||
@Override
|
||||
public boolean delete(String indexName) throws IOException {
|
||||
DeleteIndexRequest request = new DeleteIndexRequest(indexName);
|
||||
AcknowledgedResponse response = elasticsearchRestTemplate.getClient().indices().delete(request, RequestOptions.DEFAULT);
|
||||
AcknowledgedResponse response = client.indices().delete(request, RequestOptions.DEFAULT);
|
||||
return response.isAcknowledged();
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class IndexServiceImpl implements IIndexService {
|
||||
if (StrUtil.isNotEmpty(queryStr)) {
|
||||
indices = queryStr;
|
||||
}
|
||||
Response response = elasticsearchRestTemplate.getClient().getLowLevelClient()
|
||||
Response response = client.getLowLevelClient()
|
||||
.performRequest(new Request(
|
||||
"GET",
|
||||
"/_cat/indices?h=health,status,index,docsCount,docsDeleted,storeSize&s=cds:desc&format=json&index="+StrUtil.nullToEmpty(indices)
|
||||
@@ -93,7 +93,7 @@ public class IndexServiceImpl implements IIndexService {
|
||||
@Override
|
||||
public Map<String, Object> show(String indexName) throws IOException {
|
||||
GetIndexRequest request = new GetIndexRequest(indexName);
|
||||
GetIndexResponse getIndexResponse = elasticsearchRestTemplate.getClient()
|
||||
GetIndexResponse getIndexResponse = client
|
||||
.indices().get(request, RequestOptions.DEFAULT);
|
||||
MappingMetadata mappingMetadata = getIndexResponse.getMappings().get(indexName);
|
||||
Map<String, Object> mappOpenMap = mappingMetadata.getSourceAsMap();
|
||||
|
||||
+3
-5
@@ -16,7 +16,6 @@ import org.elasticsearch.search.aggregations.bucket.range.Range;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.aggregations.metrics.ParsedCardinality;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -41,10 +40,10 @@ import java.util.Map;
|
||||
*/
|
||||
@Service
|
||||
public class AggregationServiceImpl implements IAggregationService {
|
||||
private final ElasticsearchRestTemplate elasticsearchRestTemplate;
|
||||
private final RestHighLevelClient client;
|
||||
|
||||
public AggregationServiceImpl(ElasticsearchRestTemplate elasticsearchRestTemplate) {
|
||||
this.elasticsearchRestTemplate = elasticsearchRestTemplate;
|
||||
public AggregationServiceImpl(RestHighLevelClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +218,6 @@ public class AggregationServiceImpl implements IAggregationService {
|
||||
)
|
||||
).size(0);
|
||||
|
||||
RestHighLevelClient client = elasticsearchRestTemplate.getClient();
|
||||
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
|
||||
Aggregations aggregations = response.getAggregations();
|
||||
Map<String, Object> result = new HashMap<>(15);
|
||||
|
||||
+5
-4
@@ -5,6 +5,7 @@ import com.central.es.utils.SearchBuilder;
|
||||
import com.central.search.model.SearchDto;
|
||||
import com.central.search.service.ISearchService;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -19,10 +20,10 @@ import java.io.IOException;
|
||||
*/
|
||||
@Service
|
||||
public class SearchServiceImpl implements ISearchService {
|
||||
private final ElasticsearchRestTemplate elasticsearchRestTemplate;
|
||||
private final RestHighLevelClient client;
|
||||
|
||||
public SearchServiceImpl(ElasticsearchRestTemplate elasticsearchRestTemplate) {
|
||||
this.elasticsearchRestTemplate = elasticsearchRestTemplate;
|
||||
public SearchServiceImpl(RestHighLevelClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ public class SearchServiceImpl implements ISearchService {
|
||||
*/
|
||||
@Override
|
||||
public PageResult<JsonNode> strQuery(String indexName, SearchDto searchDto) throws IOException {
|
||||
return SearchBuilder.builder(elasticsearchRestTemplate, indexName)
|
||||
return SearchBuilder.builder(client, indexName)
|
||||
.setStringQuery(searchDto.getQueryStr())
|
||||
.addSort(searchDto.getSortCol(), SortOrder.DESC)
|
||||
.setIsHighlight(searchDto.getIsHighlighter())
|
||||
|
||||
+6
-9
@@ -22,8 +22,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
|
||||
import org.springframework.data.elasticsearch.UncategorizedElasticsearchException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -65,26 +64,24 @@ public class SearchBuilder {
|
||||
|
||||
/**
|
||||
* 生成SearchBuilder实例
|
||||
* @param elasticsearchTemplate
|
||||
* @param client
|
||||
* @param indexName
|
||||
*/
|
||||
public static SearchBuilder builder(ElasticsearchRestTemplate elasticsearchTemplate, String indexName) {
|
||||
public static SearchBuilder builder(RestHighLevelClient client, String indexName) {
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
SearchRequest searchRequest = new SearchRequest(indexName);
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
RestHighLevelClient client = elasticsearchTemplate.getClient();
|
||||
return new SearchBuilder(searchRequest, searchSourceBuilder, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成SearchBuilder实例
|
||||
* @param elasticsearchTemplate
|
||||
* @param client
|
||||
*/
|
||||
public static SearchBuilder builder(ElasticsearchRestTemplate elasticsearchTemplate) {
|
||||
public static SearchBuilder builder(RestHighLevelClient client) {
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
RestHighLevelClient client = elasticsearchTemplate.getClient();
|
||||
return new SearchBuilder(searchRequest, searchSourceBuilder, client);
|
||||
}
|
||||
|
||||
@@ -266,7 +263,7 @@ public class SearchBuilder {
|
||||
}
|
||||
}
|
||||
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||
throw new ElasticsearchException("failed to set highlighted value for field: " + field.getName()
|
||||
throw new UncategorizedElasticsearchException("failed to set highlighted value for field: " + field.getName()
|
||||
+ " with value: " + Arrays.toString(field.getFragments()), e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user