|
@@ -65,7 +65,7 @@ public class EsCountService {
|
|
|
}
|
|
|
Integer taskId = vo.getTaskId();
|
|
|
Integer projectId = vo.getProjectId();
|
|
|
- searchCondition = this.getCondition(taskId, projectId);
|
|
|
+ searchCondition = this.getCondition(searchCondition, taskId, projectId);
|
|
|
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
//设置查询索引
|
|
@@ -134,7 +134,7 @@ public class EsCountService {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getNestedCountDTOS(filtersAgg, field, detailDTOS);
|
|
|
+ this.getNestedCountDTOS(filtersAgg, field,topN, detailDTOS);
|
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
|
esCountDTO.setAllNumber(filtersAgg.nested().docCount());
|
|
|
}
|
|
@@ -145,14 +145,14 @@ public class EsCountService {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getChildCountDTOS(filtersAgg, field, finalFieldType, detailDTOS,esCountDTO);
|
|
|
+ this.getChildCountDTOS(filtersAgg, field, finalFieldType, topN,detailDTOS,esCountDTO);
|
|
|
});
|
|
|
} else {
|
|
|
Integer finalFieldType1 = fieldType;
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getChildAnalysisDTOS(filtersAgg, field, finalFieldType1, detailDTOS, esCountDTO);
|
|
|
+ this.getChildAnalysisDTOS(filtersAgg, field, finalFieldType1, topN,detailDTOS, esCountDTO);
|
|
|
});
|
|
|
}
|
|
|
} else if (numberList.contains(field)) {
|
|
@@ -162,14 +162,14 @@ public class EsCountService {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getNumberAnalysisDTOS(filtersAgg, field, detailDTOS);
|
|
|
+ this.getNumberAnalysisDTOS(filtersAgg, field,topN, detailDTOS);
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
// this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getTermCountDTOS(filtersAgg, field, detailDTOS);
|
|
|
+ this.getTermCountDTOS(filtersAgg, field, topN,detailDTOS);
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
@@ -183,20 +183,20 @@ public class EsCountService {
|
|
|
this.getDateAnalysisDTOS(agg, field, topN, detailDTOS,esCountDTO);
|
|
|
}
|
|
|
} else if (nestedList.contains(field)) {
|
|
|
- this.getNestedCountDTOS(agg, field, detailDTOS);
|
|
|
+ this.getNestedCountDTOS(agg, field,topN, detailDTOS);
|
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
|
esCountDTO.setAllNumber(agg.nested().docCount());
|
|
|
}
|
|
|
} else if (childList.contains(field)) {
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
- this.getChildCountDTOS(agg, field, fieldType, detailDTOS, esCountDTO);
|
|
|
+ this.getChildCountDTOS(agg, field, fieldType,topN, detailDTOS, esCountDTO);
|
|
|
} else {
|
|
|
- this.getChildAnalysisDTOS(agg, field, fieldType, detailDTOS, esCountDTO);
|
|
|
+ this.getChildAnalysisDTOS(agg, field, fieldType,topN, detailDTOS, esCountDTO);
|
|
|
}
|
|
|
} else if (numberList.contains(field)) {
|
|
|
- this.getNumberAnalysisDTOS(agg, field, detailDTOS);
|
|
|
+ this.getNumberAnalysisDTOS(agg, field,topN, detailDTOS);
|
|
|
} else {
|
|
|
- this.getTermCountDTOS(agg, field, detailDTOS);
|
|
|
+ this.getTermCountDTOS(agg, field,topN, detailDTOS);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -256,12 +256,12 @@ public class EsCountService {
|
|
|
|
|
|
/**
|
|
|
* 获取筛选条件
|
|
|
+ *
|
|
|
* @param taskId
|
|
|
* @param projectId
|
|
|
* @return
|
|
|
*/
|
|
|
- public String getCondition(Integer taskId, Integer projectId) {
|
|
|
- String searchCondition = "";
|
|
|
+ public String getCondition(String searchCondition, Integer taskId, Integer projectId) {
|
|
|
if (taskId != null) {
|
|
|
if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
searchCondition = "taskId = " + taskId + " AND " + searchCondition;
|
|
@@ -304,7 +304,13 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getTermCountDTOS(Aggregate agg, String field, List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ public void getTermCountDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
|
+ countDTO.setField(field);
|
|
|
+ countDTO.setName("其他");
|
|
|
+ countDTO.setNumber(agg.sterms().sumOtherDocCount());
|
|
|
+ countDTO.setTopN(topN);
|
|
|
+ detailDTOS.add(countDTO);
|
|
|
List<StringTermsBucket> list = agg.sterms().buckets().array();
|
|
|
list.forEach(bucket -> {
|
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
@@ -312,6 +318,7 @@ public class EsCountService {
|
|
|
Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
|
dto.setName(bucket.key().stringValue());
|
|
|
dto.setNumber(bucket.docCount());
|
|
|
+ dto.setTopN(topN);
|
|
|
if (aggregate != null) {
|
|
|
dto.setNumber(aggregate.filter().docCount());
|
|
|
}
|
|
@@ -328,7 +335,8 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getChildCountDTOS(Aggregate agg, String field,Integer fieldType, List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
+ public void getChildCountDTOS(Aggregate agg, String field,Integer fieldType, Integer topN,
|
|
|
+ List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
esCountDTO.setAllNumber(agg.children().docCount());
|
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
@@ -344,6 +352,7 @@ public class EsCountService {
|
|
|
dto.setName(termsBucket.key().stringValue());
|
|
|
dto.setNumber(termsBucket.docCount());
|
|
|
dto.setNumber(count);
|
|
|
+ dto.setTopN(topN);
|
|
|
if (dto.getNumber() > 0) {
|
|
|
detailDTOS.add(dto);
|
|
|
if (fieldType == null || fieldType != 6) {
|
|
@@ -352,6 +361,7 @@ public class EsCountService {
|
|
|
detail.setField(field);
|
|
|
detail.setName("未选择");
|
|
|
detail.setNumber(docCount);
|
|
|
+ detail.setTopN(topN);
|
|
|
if (!detailDTOS.contains(detail)) {
|
|
|
detailDTOS.add(detail);
|
|
|
}
|
|
@@ -369,7 +379,8 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getChildAnalysisDTOS(Aggregate agg, String field,Integer fieldType, List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
+ public void getChildAnalysisDTOS(Aggregate agg, String field,Integer fieldType,Integer topN,
|
|
|
+ List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
|
list.forEach(bucket -> {
|
|
@@ -381,6 +392,7 @@ public class EsCountService {
|
|
|
dto.setField(field);
|
|
|
dto.setName(termsBucket.key().stringValue());
|
|
|
dto.setNumber(termsBucket.docCount());
|
|
|
+ dto.setTopN(topN);
|
|
|
if (dto.getNumber() > 0) {
|
|
|
detailDTOS.add(dto);
|
|
|
if (fieldType == null || fieldType != 6) {
|
|
@@ -389,6 +401,7 @@ public class EsCountService {
|
|
|
detail.setField(field);
|
|
|
detail.setName("未选择");
|
|
|
detail.setNumber(docCount);
|
|
|
+ detail.setTopN(topN);
|
|
|
if (!detailDTOS.contains(detail)) {
|
|
|
detailDTOS.add(detail);
|
|
|
}
|
|
@@ -405,13 +418,14 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getNumberAnalysisDTOS(Aggregate agg, String field, List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ public void getNumberAnalysisDTOS(Aggregate agg, String field,Integer topN, List<EsCountDetailDTO> detailDTOS) {
|
|
|
List<RangeBucket> list = agg.range().buckets().array();
|
|
|
for (RangeBucket bucket : list) {
|
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
|
dto.setField(field);
|
|
|
dto.setName(bucket.key());
|
|
|
dto.setNumber(bucket.docCount());
|
|
|
+ dto.setTopN(topN);
|
|
|
if (dto.getNumber() > 0) {
|
|
|
detailDTOS.add(dto);
|
|
|
}
|
|
@@ -451,10 +465,12 @@ public class EsCountService {
|
|
|
dto.setField(field);
|
|
|
dto.setName(year + "-H1");
|
|
|
dto.setNumber(h1Count);
|
|
|
+ dto.setTopN(topN);
|
|
|
EsCountDetailDTO dto2 = new EsCountDetailDTO();
|
|
|
dto2.setField(field);
|
|
|
dto2.setName(year + "-H2");
|
|
|
dto2.setNumber(h2Count);
|
|
|
+ dto2.setTopN(topN);
|
|
|
if (month.before(halfYearDate)) {
|
|
|
h1Count += histogramBucket.docCount();
|
|
|
dto.setNumber(h1Count);
|
|
@@ -482,6 +498,7 @@ public class EsCountService {
|
|
|
Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
|
dto.setName(bucket.keyAsString());
|
|
|
dto.setNumber(bucket.docCount());
|
|
|
+ dto.setTopN(topN);
|
|
|
if (aggregate != null) {
|
|
|
dto.setNumber(aggregate.filter().docCount());
|
|
|
}
|
|
@@ -515,6 +532,7 @@ public class EsCountService {
|
|
|
dto.setField(field);
|
|
|
dto.setName(bucket.key());
|
|
|
dto.setNumber(bucket.docCount());
|
|
|
+ dto.setTopN(topN);
|
|
|
if (dto.getNumber() > 0) {
|
|
|
esCountDetailDTOS.add(dto);
|
|
|
}
|
|
@@ -533,7 +551,7 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getNestedCountDTOS(Aggregate agg, String field, List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ public void getNestedCountDTOS(Aggregate agg, String field,Integer topN, List<EsCountDetailDTO> detailDTOS) {
|
|
|
Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
|
List<StringTermsBucket> list = termsAgg.sterms().buckets().array();
|
|
|
list.forEach(bucket -> {
|
|
@@ -542,6 +560,7 @@ public class EsCountService {
|
|
|
Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
|
dto.setName(bucket.key().stringValue());
|
|
|
dto.setNumber(bucket.docCount());
|
|
|
+ dto.setTopN(topN);
|
|
|
if (aggregate != null) {
|
|
|
dto.setNumber(aggregate.filter().docCount());
|
|
|
}
|