|
@@ -8,6 +8,8 @@ import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
|
|
import cn.cslg.pas.common.vo.EsConfigVO;
|
|
import cn.cslg.pas.common.vo.EsConfigVO;
|
|
import cn.cslg.pas.common.vo.business.EsCountVO;
|
|
import cn.cslg.pas.common.vo.business.EsCountVO;
|
|
import cn.cslg.pas.domain.es.Patent;
|
|
import cn.cslg.pas.domain.es.Patent;
|
|
|
|
+import cn.cslg.pas.factorys.EsAnalysisBuilderFactory.EsAnalysisBuilderFactory;
|
|
|
|
+import cn.cslg.pas.factorys.EsAnalysisBuilderFactory.IEsAnalysisBuilder;
|
|
import cn.cslg.pas.factorys.EsCountBuilderFactory.EsCountBuilderFactory;
|
|
import cn.cslg.pas.factorys.EsCountBuilderFactory.EsCountBuilderFactory;
|
|
import cn.cslg.pas.factorys.EsCountBuilderFactory.IEsCountBuilder;
|
|
import cn.cslg.pas.factorys.EsCountBuilderFactory.IEsCountBuilder;
|
|
import cn.cslg.pas.service.business.CommonService;
|
|
import cn.cslg.pas.service.business.CommonService;
|
|
@@ -35,14 +37,18 @@ import java.util.stream.Collectors;
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
public class EsCountService {
|
|
public class EsCountService {
|
|
private final List<String> childList = Arrays.asList("field");
|
|
private final List<String> childList = Arrays.asList("field");
|
|
- private final List<String> nestedList = Arrays.asList("PA", "IN", "PE");
|
|
|
|
- private final List<String> dateList = Arrays.asList("PD", "AD");
|
|
|
|
|
|
+ private final List<String> nestedList = Arrays.asList("PA", "IN", "PE", "SAT", "MAT", "SRH", "MRH");
|
|
|
|
+ private final List<String> dateList = Arrays.asList("PD", "AD", "GD");
|
|
|
|
+ private final List<String> numberList = Arrays.asList("QPN", "QDPN", "SFN", "IFN", "PFN");
|
|
|
|
+
|
|
|
|
|
|
private final ElasticsearchClient client;
|
|
private final ElasticsearchClient client;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private EsCountBuilderFactory esCountBuilderFactory;
|
|
private EsCountBuilderFactory esCountBuilderFactory;
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ private EsAnalysisBuilderFactory esAnalysisBuilderFactory;
|
|
|
|
+ @Autowired
|
|
private FormatQueryService formatQueryService;
|
|
private FormatQueryService formatQueryService;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -89,35 +95,35 @@ public class EsCountService {
|
|
List<FiltersBucket> filtersBuckets = agg.filters().buckets().array();
|
|
List<FiltersBucket> filtersBuckets = agg.filters().buckets().array();
|
|
if (dateList.contains(field)) {
|
|
if (dateList.contains(field)) {
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
- this.getFiltersCountDTO(filtersBucket, condition,detailDTOS);
|
|
|
|
|
|
+ this.getFiltersCountDTO(filtersBucket, condition, detailDTOS);
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
- this.getDateCountDTOS(filtersAgg, field,topN,detailDTOS);
|
|
|
|
|
|
+ this.getDateCountDTOS(filtersAgg, field, topN, detailDTOS);
|
|
});
|
|
});
|
|
} else if (nestedList.contains(field)) {
|
|
} else if (nestedList.contains(field)) {
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
- this.getFiltersCountDTO(filtersBucket, condition,detailDTOS);
|
|
|
|
|
|
+ this.getFiltersCountDTO(filtersBucket, condition, detailDTOS);
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
- this.getNestedCountDTOS(filtersAgg, field,detailDTOS);
|
|
|
|
|
|
+ this.getNestedCountDTOS(filtersAgg, field, detailDTOS);
|
|
});
|
|
});
|
|
} else if (childList.contains(field)) {
|
|
} else if (childList.contains(field)) {
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
- this.getFiltersCountDTO(filtersBucket, condition,detailDTOS);
|
|
|
|
|
|
+ this.getFiltersCountDTO(filtersBucket, condition, detailDTOS);
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
- this.getChildCountDTOS(filtersAgg, field,detailDTOS);
|
|
|
|
|
|
+ this.getChildCountDTOS(filtersAgg, field, detailDTOS);
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
- this.getFiltersCountDTO(filtersBucket, condition,detailDTOS);
|
|
|
|
|
|
+ this.getFiltersCountDTO(filtersBucket, condition, detailDTOS);
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
this.getTermCountDTOS(filtersAgg, field, detailDTOS);
|
|
this.getTermCountDTOS(filtersAgg, field, detailDTOS);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- this.getFilterCountDTO(agg, condition,detailDTOS);
|
|
|
|
|
|
+ this.getFilterCountDTO(agg, condition, detailDTOS);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
if (dateList.contains(field)) {
|
|
if (dateList.contains(field)) {
|
|
- this.getDateCountDTOS(agg, field,topN, detailDTOS);
|
|
|
|
|
|
+ this.getDateCountDTOS(agg, field, topN, detailDTOS);
|
|
} else if (nestedList.contains(field)) {
|
|
} else if (nestedList.contains(field)) {
|
|
this.getNestedCountDTOS(agg, field, detailDTOS);
|
|
this.getNestedCountDTOS(agg, field, detailDTOS);
|
|
} else if (childList.contains(field)) {
|
|
} else if (childList.contains(field)) {
|
|
@@ -131,6 +137,57 @@ public class EsCountService {
|
|
return esCountDTO;
|
|
return esCountDTO;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public EsCountDTO esAnalysisSearch(List<EsCountVO> countVOS) throws Exception {
|
|
|
|
+ EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
|
+ List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
|
|
+ for (EsCountVO vo : countVOS) {
|
|
|
|
+ String field = vo.getField();
|
|
|
|
+ Integer topN = vo.getTopN();
|
|
|
|
+ Boolean ifHaveChild = vo.getIfHaveChild();
|
|
|
|
+ List<String> values = vo.getValues();
|
|
|
|
+ //查询es返回数据
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+ builder.index("patent");
|
|
|
|
+ IEsAnalysisBuilder iEsAnalysisBuilder = null;
|
|
|
|
+ String json = CommonService.readJsonFile("esAnalysis.json");
|
|
|
|
+ List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
|
|
+ EsConfigVO esConfigVO = esConfigVOS.stream().filter(item -> item.getField().equals(field))
|
|
|
|
+ .findFirst().orElse(null);
|
|
|
|
+ if (esConfigVO != null) {
|
|
|
|
+ iEsAnalysisBuilder = esAnalysisBuilderFactory.getClass(esConfigVO.getEsClass());
|
|
|
|
+ iEsAnalysisBuilder.setField(esConfigVO.getEsField());
|
|
|
|
+ iEsAnalysisBuilder.setTopN(topN);
|
|
|
|
+ iEsAnalysisBuilder.setIfHaveChild(ifHaveChild);
|
|
|
|
+ if (iEsAnalysisBuilder.getField().contains(".")) {
|
|
|
|
+ String path = iEsAnalysisBuilder.getField().substring(0, iEsAnalysisBuilder.getField().indexOf("."));
|
|
|
|
+ iEsAnalysisBuilder.setPath(path);
|
|
|
|
+ }
|
|
|
|
+ for (String value : values) {
|
|
|
|
+ iEsAnalysisBuilder.setFieldValue(value);
|
|
|
|
+ Aggregation aggregation = iEsAnalysisBuilder.createAnalyseAgg();
|
|
|
|
+ builder.aggregations("Agg", aggregation);
|
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
+
|
|
|
|
+ Aggregate agg = response.aggregations().get("Agg");
|
|
|
|
+ if (dateList.contains(field)) {
|
|
|
|
+ this.getDateCountDTOS(agg, field, topN, detailDTOS);
|
|
|
|
+ } else if (nestedList.contains(field)) {
|
|
|
|
+ this.getNestedCountDTOS(agg, field, detailDTOS);
|
|
|
|
+ } else if (childList.contains(field)) {
|
|
|
|
+ this.getChildCountDTOS(agg, field, detailDTOS);
|
|
|
|
+ } else if (childList.contains(field)) {
|
|
|
|
+ this.getChildCountDTOS(agg, field, detailDTOS);
|
|
|
|
+ } else {
|
|
|
|
+ this.getTermCountDTOS(agg, field, detailDTOS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ esCountDTO.setDetailDTOS(detailDTOS);
|
|
|
|
+ return esCountDTO;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取聚合后的aggregation
|
|
* 获取聚合后的aggregation
|
|
*
|
|
*
|
|
@@ -170,11 +227,12 @@ public class EsCountService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取Filter聚合返回数据
|
|
* 获取Filter聚合返回数据
|
|
|
|
+ *
|
|
* @param agg
|
|
* @param agg
|
|
* @param condition
|
|
* @param condition
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public void getFilterCountDTO(Aggregate agg,String condition,List<EsCountDetailDTO> detailDTOS) {
|
|
|
|
|
|
+ public void getFilterCountDTO(Aggregate agg, String condition, List<EsCountDetailDTO> detailDTOS) {
|
|
EsCountDetailDTO filterDTO = new EsCountDetailDTO();
|
|
EsCountDetailDTO filterDTO = new EsCountDetailDTO();
|
|
filterDTO.setField("condition");
|
|
filterDTO.setField("condition");
|
|
filterDTO.setName(condition);
|
|
filterDTO.setName(condition);
|
|
@@ -186,11 +244,12 @@ public class EsCountService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取Filters聚合返回数据
|
|
* 获取Filters聚合返回数据
|
|
|
|
+ *
|
|
* @param filtersBucket
|
|
* @param filtersBucket
|
|
* @param condition
|
|
* @param condition
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public void getFiltersCountDTO(FiltersBucket filtersBucket,String condition,List<EsCountDetailDTO> detailDTOS) {
|
|
|
|
|
|
+ public void getFiltersCountDTO(FiltersBucket filtersBucket, String condition, List<EsCountDetailDTO> detailDTOS) {
|
|
EsCountDetailDTO filtersDTO = new EsCountDetailDTO();
|
|
EsCountDetailDTO filtersDTO = new EsCountDetailDTO();
|
|
filtersDTO.setField("condition");
|
|
filtersDTO.setField("condition");
|
|
filtersDTO.setName(condition);
|
|
filtersDTO.setName(condition);
|
|
@@ -231,7 +290,7 @@ public class EsCountService {
|
|
* @param field
|
|
* @param field
|
|
* @param detailDTOS
|
|
* @param detailDTOS
|
|
*/
|
|
*/
|
|
- public void getChildCountDTOS(Aggregate agg, String field,List<EsCountDetailDTO> detailDTOS) {
|
|
|
|
|
|
+ public void getChildCountDTOS(Aggregate agg, String field, List<EsCountDetailDTO> detailDTOS) {
|
|
Aggregate childAgg = agg.children().aggregations().get("child_agg");
|
|
Aggregate childAgg = agg.children().aggregations().get("child_agg");
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
list.forEach(bucket -> {
|
|
list.forEach(bucket -> {
|
|
@@ -256,7 +315,7 @@ public class EsCountService {
|
|
* @param field
|
|
* @param field
|
|
* @param detailDTOS
|
|
* @param detailDTOS
|
|
*/
|
|
*/
|
|
- public void getDateCountDTOS(Aggregate agg, String field,Integer topN,List<EsCountDetailDTO> detailDTOS) {
|
|
|
|
|
|
+ public void getDateCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS) {
|
|
List<DateHistogramBucket> list = agg.dateHistogram().buckets().array();
|
|
List<DateHistogramBucket> list = agg.dateHistogram().buckets().array();
|
|
List<EsCountDetailDTO> esCountDetailDTOS = new ArrayList<>();
|
|
List<EsCountDetailDTO> esCountDetailDTOS = new ArrayList<>();
|
|
list.forEach(bucket -> {
|
|
list.forEach(bucket -> {
|
|
@@ -286,7 +345,7 @@ public class EsCountService {
|
|
* @param field
|
|
* @param field
|
|
* @param detailDTOS
|
|
* @param detailDTOS
|
|
*/
|
|
*/
|
|
- public void getNestedCountDTOS(Aggregate agg, String field,List<EsCountDetailDTO> detailDTOS) {
|
|
|
|
|
|
+ public void getNestedCountDTOS(Aggregate agg, String field, List<EsCountDetailDTO> detailDTOS) {
|
|
Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
List<StringTermsBucket> list = termsAgg.sterms().buckets().array();
|
|
List<StringTermsBucket> list = termsAgg.sterms().buckets().array();
|
|
list.forEach(bucket -> {
|
|
list.forEach(bucket -> {
|