feat: There is no way the, rest es conf
This commit is contained in:
@@ -118,6 +118,11 @@ public interface ElasticsearchService {
|
|||||||
*/
|
*/
|
||||||
Map<String, Object> searchDataById(String index, String type, String id, String fields);
|
Map<String, Object> searchDataById(String index, String type, String id, String fields);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用索引查询所有
|
||||||
|
*/
|
||||||
|
|
||||||
|
List<Map<String,Object>> searchAll(String index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用分词查询
|
* 使用分词查询
|
||||||
|
|||||||
+55
@@ -8,6 +8,7 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
|||||||
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
||||||
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
|
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
|
||||||
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
|
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
|
||||||
|
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequestBuilder;
|
||||||
import org.elasticsearch.action.bulk.BulkRequest;
|
import org.elasticsearch.action.bulk.BulkRequest;
|
||||||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
||||||
import org.elasticsearch.action.bulk.BulkResponse;
|
import org.elasticsearch.action.bulk.BulkResponse;
|
||||||
@@ -24,11 +25,16 @@ import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
|||||||
import org.elasticsearch.action.update.UpdateRequest;
|
import org.elasticsearch.action.update.UpdateRequest;
|
||||||
import org.elasticsearch.action.update.UpdateResponse;
|
import org.elasticsearch.action.update.UpdateResponse;
|
||||||
import org.elasticsearch.client.transport.TransportClient;
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.text.Text;
|
import org.elasticsearch.common.text.Text;
|
||||||
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||||
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
|
import org.elasticsearch.search.Scroll;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
|
import org.elasticsearch.search.SearchHits;
|
||||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||||
import org.elasticsearch.search.aggregations.BucketOrder;
|
import org.elasticsearch.search.aggregations.BucketOrder;
|
||||||
import org.elasticsearch.search.aggregations.bucket.range.Range;
|
import org.elasticsearch.search.aggregations.bucket.range.Range;
|
||||||
@@ -36,6 +42,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
|
|||||||
import org.elasticsearch.search.aggregations.metrics.Avg;
|
import org.elasticsearch.search.aggregations.metrics.Avg;
|
||||||
import org.elasticsearch.search.aggregations.metrics.Max;
|
import org.elasticsearch.search.aggregations.metrics.Max;
|
||||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||||
|
import org.elasticsearch.search.sort.FieldSortBuilder;
|
||||||
import org.elasticsearch.search.sort.SortOrder;
|
import org.elasticsearch.search.sort.SortOrder;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -273,6 +280,54 @@ public class ElasticsearchServiceImpl implements ElasticsearchService {
|
|||||||
return getResponse.getSource();
|
return getResponse.getSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用索引查询所有
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Map<String, Object>> searchAll(String index) {
|
||||||
|
List<Map<String, Object>> sourceList = new ArrayList<Map<String, Object>>();
|
||||||
|
|
||||||
|
//1、指定es集群 cluster.name 是固定的key值,my-application是ES集群的名称
|
||||||
|
// Settings settings = Settings.builder().put("cluster.name", "my-application").build();
|
||||||
|
QueryBuilder qBuilder = QueryBuilders.matchAllQuery();
|
||||||
|
SearchResponse sResponse = client.prepareSearch(index)
|
||||||
|
.setQuery(qBuilder).setTrackTotalHits(true)
|
||||||
|
.get();
|
||||||
|
SearchHits hits = sResponse.getHits();
|
||||||
|
if(hits.getTotalHits().value > 0){
|
||||||
|
SearchResponse scrollResp = search(index,qBuilder, 1,(int) hits.getTotalHits().value);
|
||||||
|
for (SearchHit hit : scrollResp.getHits().getHits()) {
|
||||||
|
sourceList.add(hit.getSourceAsMap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sourceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SearchResponse search(String index, QueryBuilder query,int page, int size) {
|
||||||
|
|
||||||
|
updateIndex(index, page,size);
|
||||||
|
|
||||||
|
SearchResponse searchResponse = client.prepareSearch(index)
|
||||||
|
.setScroll(new TimeValue(360000))
|
||||||
|
.setQuery(query).setTrackTotalHits(true).setSize(size)
|
||||||
|
.get();
|
||||||
|
return searchResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新索引的max_result_window参数
|
||||||
|
private boolean updateIndex(String indices, int from,int size) {
|
||||||
|
int records = from * size + size;
|
||||||
|
if (records <= 10000) return true;
|
||||||
|
AcknowledgedResponse indexResponse = client.admin().indices()
|
||||||
|
.prepareUpdateSettings(indices)
|
||||||
|
.setSettings(Settings.builder()
|
||||||
|
.put("index.max_result_window", records)
|
||||||
|
.build()
|
||||||
|
).get();
|
||||||
|
return indexResponse.isAcknowledged();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用分词查询
|
* 使用分词查询
|
||||||
|
|||||||
@@ -100,12 +100,10 @@ public class ResetSearchCenterService {
|
|||||||
|
|
||||||
Boolean getStandIndex = elasticsearchService.isIndexExist("stand");
|
Boolean getStandIndex = elasticsearchService.isIndexExist("stand");
|
||||||
|
|
||||||
List<Map<String, Object>> searchListData = elasticsearchService.searchListData("stand","","","");
|
List<Map<String, Object>> searchListData = elasticsearchService.searchAll("stand");
|
||||||
|
|
||||||
List<String> esIdList = searchListData.stream().map(stringObjectMap -> stringObjectMap.get("id").toString()).collect(Collectors.toList());
|
List<String> esIdList = searchListData.stream().map(stringObjectMap -> stringObjectMap.get("id").toString()).collect(Collectors.toList());
|
||||||
|
|
||||||
logger.info(searchListData.toString());
|
|
||||||
logger.info(esIdList.toString());
|
|
||||||
page.setValidFlag("0");
|
page.setValidFlag("0");
|
||||||
if(searchCenter.getIdList() != null && !searchCenter.getIdList().isEmpty()){
|
if(searchCenter.getIdList() != null && !searchCenter.getIdList().isEmpty()){
|
||||||
String[] result = searchCenter.getIdList().toArray(new String[0]);
|
String[] result = searchCenter.getIdList().toArray(new String[0]);
|
||||||
@@ -170,15 +168,15 @@ public class ResetSearchCenterService {
|
|||||||
elasticsearchService.deleteBatchId(delList,"stand");
|
elasticsearchService.deleteBatchId(delList,"stand");
|
||||||
elasticsearchService.deleteBatchId(delList,"fulltextserch");
|
elasticsearchService.deleteBatchId(delList,"fulltextserch");
|
||||||
}
|
}
|
||||||
logger.info("重置国内外标准:新增-"+ countAddSuccess + "条 更新-"+countUpdateSuccess+"条(国内外标准共:"+rowsStand.size()+"条)删除-共"+delList.size()+"条数据");
|
logger.info("重置国内外标准:新增-"+ countAddSuccess + "条 更新-"+countUpdateSuccess+"条(国内外标准共:"+0+"条)删除-共"+delList.size()+"条数据");
|
||||||
return Result.success("重置国内外标准:新增-"+ countAddSuccess + "条 更新-"+countUpdateSuccess+"条(国内外标准共:"+rowsStand.size()+"条)删除-共"+delList.size()+"条数据");
|
return Result.success("重置国内外标准:新增-"+ countAddSuccess + "条 更新-"+countUpdateSuccess+"条(国内外标准共:"+0+"条)删除-共"+delList.size()+"条数据");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
public ResponseMessage resetLawsSearchCenter(SarLawsStandInfoPage sarLawsInfoEOPage,SearchCenter searchCenter) throws Exception{
|
public ResponseMessage resetLawsSearchCenter(SarLawsStandInfoPage sarLawsInfoEOPage,SearchCenter searchCenter) throws Exception{
|
||||||
Boolean getLawsIndex = elasticsearchService.isIndexExist("laws");
|
Boolean getLawsIndex = elasticsearchService.isIndexExist("laws");
|
||||||
|
|
||||||
List<Map<String, Object>> searchListData = elasticsearchService.searchListData("laws","","","");
|
List<Map<String, Object>> searchListData = elasticsearchService.searchAll("laws");
|
||||||
|
|
||||||
List<String> esIdList = searchListData.stream().map(stringObjectMap -> stringObjectMap.get("id").toString()).collect(Collectors.toList());
|
List<String> esIdList = searchListData.stream().map(stringObjectMap -> stringObjectMap.get("id").toString()).collect(Collectors.toList());
|
||||||
|
|
||||||
@@ -262,7 +260,7 @@ public class ResetSearchCenterService {
|
|||||||
public ResponseMessage resetBussStandSearchCenter(SarBussionessStandEOPage sarBussionessStandEOPage,SearchCenter searchCenter) throws Exception{
|
public ResponseMessage resetBussStandSearchCenter(SarBussionessStandEOPage sarBussionessStandEOPage,SearchCenter searchCenter) throws Exception{
|
||||||
Boolean getbussstandIndex = elasticsearchService.isIndexExist("bussstand");
|
Boolean getbussstandIndex = elasticsearchService.isIndexExist("bussstand");
|
||||||
|
|
||||||
List<Map<String, Object>> searchListData = elasticsearchService.searchListData("bussstand","","","");
|
List<Map<String, Object>> searchListData = elasticsearchService.searchAll("bussstand");
|
||||||
|
|
||||||
List<String> esIdList = searchListData.stream().map(stringObjectMap -> stringObjectMap.get("id").toString()).collect(Collectors.toList());
|
List<String> esIdList = searchListData.stream().map(stringObjectMap -> stringObjectMap.get("id").toString()).collect(Collectors.toList());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user