|
@@ -133,13 +133,13 @@ public class EsCountService {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
this.getFiltersCountDTO(filtersBucket, condition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getDateCountDTOS(filtersAgg, field, topN, detailDTOS);
|
|
|
+ this.getDateCountDTOS(filtersAgg, field, topN, detailDTOS,esCountDTO);
|
|
|
});
|
|
|
} else if (nestedList.contains(field)) {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
this.getFiltersCountDTO(filtersBucket, condition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getNestedCountDTOS(filtersAgg, field, detailDTOS);
|
|
|
+ this.getNestedCountDTOS(filtersAgg, field, detailDTOS,esCountDTO);
|
|
|
});
|
|
|
} else if (childList.contains(field)) {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
@@ -159,9 +159,9 @@ public class EsCountService {
|
|
|
}
|
|
|
} else {
|
|
|
if (dateList.contains(field)) {
|
|
|
- this.getDateCountDTOS(agg, field, topN, detailDTOS);
|
|
|
+ this.getDateCountDTOS(agg, field, topN, detailDTOS,esCountDTO);
|
|
|
} else if (nestedList.contains(field)) {
|
|
|
- this.getNestedCountDTOS(agg, field, detailDTOS);
|
|
|
+ this.getNestedCountDTOS(agg, field, detailDTOS,esCountDTO);
|
|
|
} else if (childList.contains(field)) {
|
|
|
this.getChildCountDTOS(agg, field, detailDTOS);
|
|
|
} else {
|
|
@@ -263,11 +263,11 @@ public class EsCountService {
|
|
|
|
|
|
Aggregate agg = response.aggregations().get("Agg");
|
|
|
if (dateList.contains(field)) {
|
|
|
- this.getDateAnalysisDTOS(agg, field, topN, detailDTOS);
|
|
|
+ this.getDateAnalysisDTOS(agg, field, topN, detailDTOS,esCountDTO);
|
|
|
} else if (nestedList.contains(field)) {
|
|
|
- this.getNestedCountDTOS(agg, field, detailDTOS);
|
|
|
+ this.getNestedCountDTOS(agg, field, detailDTOS,esCountDTO);
|
|
|
} else if (childList.contains(field)) {
|
|
|
- this.getChildAnalysisDTOS(agg, field, detailDTOS);
|
|
|
+ this.getChildAnalysisDTOS(agg, field, detailDTOS, esCountDTO);
|
|
|
} else if (numberList.contains(field)) {
|
|
|
this.getNumberAnalysisDTOS(agg, field, detailDTOS);
|
|
|
} else {
|
|
@@ -363,11 +363,11 @@ public class EsCountService {
|
|
|
|
|
|
Aggregate agg = response.aggregations().get("Agg");
|
|
|
if (dateList.contains(field)) {
|
|
|
- this.getDateAnalysisDTOS(agg, field, topN, detailDTOS);
|
|
|
+ this.getDateAnalysisDTOS(agg, field, topN, detailDTOS,esCountDTO);
|
|
|
} else if (nestedList.contains(field)) {
|
|
|
- this.getNestedCountDTOS(agg, field, detailDTOS);
|
|
|
+ this.getNestedCountDTOS(agg, field, detailDTOS,esCountDTO);
|
|
|
} else if (childList.contains(field)) {
|
|
|
- this.getChildAnalysisDTOS(agg, field, detailDTOS);
|
|
|
+ this.getChildAnalysisDTOS(agg, field, detailDTOS, esCountDTO);
|
|
|
} else if (numberList.contains(field)) {
|
|
|
this.getNumberAnalysisDTOS(agg, field, detailDTOS);
|
|
|
} else {
|
|
@@ -486,10 +486,10 @@ public class EsCountService {
|
|
|
* @param 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("childAgg");
|
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
|
list.forEach(bucket -> {
|
|
|
- Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
|
+ Aggregate aggregate = bucket.aggregations().get("termAgg");
|
|
|
List<StringTermsBucket> termsBuckets = aggregate.sterms().buckets().array();
|
|
|
termsBuckets.forEach(termsBucket -> {
|
|
|
Aggregate termAgg = termsBucket.aggregations().get("filterAgg");
|
|
@@ -498,9 +498,18 @@ public class EsCountService {
|
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
|
dto.setField(field);
|
|
|
dto.setName(termsBucket.key().stringValue());
|
|
|
+ dto.setNumber(termsBucket.docCount());
|
|
|
dto.setNumber(count);
|
|
|
if (dto.getNumber() > 0) {
|
|
|
detailDTOS.add(dto);
|
|
|
+ Long docCount = aggregate.sterms().sumOtherDocCount();
|
|
|
+ EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
|
+ detail.setField(field);
|
|
|
+ detail.setName("未选择");
|
|
|
+ detail.setNumber(docCount);
|
|
|
+ if (!detailDTOS.contains(detail)) {
|
|
|
+ detailDTOS.add(detail);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -514,33 +523,31 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getChildAnalysisDTOS(Aggregate agg, String field, List<EsCountDetailDTO> detailDTOS) {
|
|
|
- Aggregate childAgg = agg.children().aggregations().get("child_agg");
|
|
|
+ public void getChildAnalysisDTOS(Aggregate agg, String field, List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO) {
|
|
|
+ Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
List<StringTermsBucket> list = childAgg.sterms().buckets().array();
|
|
|
- for (StringTermsBucket bucket : list) {
|
|
|
- Aggregate termAgg = bucket.aggregations().get("term_agg");
|
|
|
- List<StringTermsBucket> bucketList = termAgg.sterms().buckets().array();
|
|
|
- if (!CollectionUtils.isEmpty(bucketList)) {
|
|
|
- for (StringTermsBucket termsBucket : bucketList) {
|
|
|
- EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
|
- dto.setField(field);
|
|
|
- dto.setName(termsBucket.key().stringValue());
|
|
|
- Aggregate aggregate = termsBucket.aggregations().get("filterAgg");
|
|
|
- List<FiltersBucket> filtersBuckets = aggregate.filters().buckets().array();
|
|
|
- for (int i = 0; i < filtersBuckets.size() - 1; i++) {
|
|
|
- FiltersBucket filtersBucket = filtersBuckets.get(i);
|
|
|
- if (filtersBucket.docCount() > 0) {
|
|
|
- dto.setNumber(filtersBucket.docCount());
|
|
|
- if (dto.getNumber() > 0) {
|
|
|
- detailDTOS.add(dto);
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
+ list.forEach(bucket -> {
|
|
|
+ esCountDTO.setAllNumber(bucket.docCount());
|
|
|
+ Aggregate aggregate = bucket.aggregations().get("termAgg");
|
|
|
+ List<StringTermsBucket> termsBuckets = aggregate.sterms().buckets().array();
|
|
|
+ termsBuckets.forEach(termsBucket -> {
|
|
|
+ EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
|
+ dto.setField(field);
|
|
|
+ dto.setName(termsBucket.key().stringValue());
|
|
|
+ dto.setNumber(termsBucket.docCount());
|
|
|
+ if (dto.getNumber() > 0) {
|
|
|
+ detailDTOS.add(dto);
|
|
|
+ Long docCount = aggregate.sterms().sumOtherDocCount();
|
|
|
+ EsCountDetailDTO detail = new EsCountDetailDTO();
|
|
|
+ detail.setField(field);
|
|
|
+ detail.setName("未选择");
|
|
|
+ detail.setNumber(docCount);
|
|
|
+ if (!detailDTOS.contains(detail)) {
|
|
|
+ detailDTOS.add(detail);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -570,8 +577,9 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @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,EsCountDTO esCountDTO) {
|
|
|
List<DateHistogramBucket> list = agg.dateHistogram().buckets().array();
|
|
|
+ esCountDTO.setAllNumber(Long.valueOf(String.valueOf(list.size())));
|
|
|
List<EsCountDetailDTO> esCountDetailDTOS = new ArrayList<>();
|
|
|
list.forEach(bucket -> {
|
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
@@ -601,8 +609,9 @@ public class EsCountService {
|
|
|
* @param topN
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getDateAnalysisDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ public void getDateAnalysisDTOS(Aggregate agg, String field, Integer topN, List<EsCountDetailDTO> detailDTOS,EsCountDTO esCountDTO) {
|
|
|
List<RangeBucket> list1 = agg.dateRange().buckets().array();
|
|
|
+ esCountDTO.setAllNumber(Long.valueOf(String.valueOf(list1.size())));
|
|
|
List<EsCountDetailDTO> esCountDetailDTOS = new ArrayList<>();
|
|
|
for (RangeBucket bucket : list1) {
|
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
@@ -627,7 +636,8 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getNestedCountDTOS(Aggregate agg, String field, List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ public void getNestedCountDTOS(Aggregate agg, String field, List<EsCountDetailDTO> detailDTOS,EsCountDTO esCountDTO) {
|
|
|
+ esCountDTO.setAllNumber(agg.nested().docCount());
|
|
|
Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
|
List<StringTermsBucket> list = termsAgg.sterms().buckets().array();
|
|
|
list.forEach(bucket -> {
|
|
@@ -721,13 +731,6 @@ public class EsCountService {
|
|
|
iEsCountAnalysisBuilder.setPath(path);
|
|
|
}
|
|
|
aggregation = iEsCountAnalysisBuilder.createCountAnalyseAgg();
|
|
|
- if (StringUtils.isNotEmpty(valueOne) || StringUtils.isNotEmpty(valueTwo)) {
|
|
|
-
|
|
|
- } else if (!CollectionUtils.isEmpty(values)) {
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- }
|
|
|
}
|
|
|
if (query != null) {
|
|
|
Query finalQuery = query;
|
|
@@ -752,27 +755,35 @@ public class EsCountService {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getDateCountDTOS(filtersAgg, field, topN, detailDTOS);
|
|
|
+ this.getDateCountDTOS(filtersAgg, field, topN, detailDTOS,esCountDTO);
|
|
|
});
|
|
|
} else {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getDateAnalysisDTOS(filtersAgg, field, topN, detailDTOS);
|
|
|
+ this.getDateAnalysisDTOS(filtersAgg, field, topN, detailDTOS,esCountDTO);
|
|
|
});
|
|
|
}
|
|
|
} else if (nestedList.contains(field)) {
|
|
|
filtersBuckets.forEach(filtersBucket -> {
|
|
|
this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getNestedCountDTOS(filtersAgg, field, detailDTOS);
|
|
|
+ this.getNestedCountDTOS(filtersAgg, field, detailDTOS,esCountDTO);
|
|
|
});
|
|
|
} else if (childList.contains(field)) {
|
|
|
- filtersBuckets.forEach(filtersBucket -> {
|
|
|
- this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
- Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
- this.getChildCountDTOS(filtersAgg, field, detailDTOS);
|
|
|
- });
|
|
|
+ if (CollectionUtils.isEmpty(values)) {
|
|
|
+ filtersBuckets.forEach(filtersBucket -> {
|
|
|
+ this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
+ Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
+ this.getChildCountDTOS(filtersAgg, field, detailDTOS);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ filtersBuckets.forEach(filtersBucket -> {
|
|
|
+ this.getFiltersCountDTO(filtersBucket, finalSearchCondition, detailDTOS);
|
|
|
+ Aggregate filtersAgg = filtersBucket.aggregations().get("filters_agg");
|
|
|
+ this.getChildAnalysisDTOS(filtersAgg, field, detailDTOS,esCountDTO);
|
|
|
+ });
|
|
|
+ }
|
|
|
} else if (numberList.contains(field)) {
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
|
|
@@ -796,14 +807,18 @@ public class EsCountService {
|
|
|
} else {
|
|
|
if (dateList.contains(field)) {
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
- this.getDateCountDTOS(agg, field, topN, detailDTOS);
|
|
|
+ this.getDateCountDTOS(agg, field, topN, detailDTOS,esCountDTO);
|
|
|
} else {
|
|
|
- this.getDateAnalysisDTOS(agg, field, topN, detailDTOS);
|
|
|
+ this.getDateAnalysisDTOS(agg, field, topN, detailDTOS,esCountDTO);
|
|
|
}
|
|
|
} else if (nestedList.contains(field)) {
|
|
|
- this.getNestedCountDTOS(agg, field, detailDTOS);
|
|
|
+ this.getNestedCountDTOS(agg, field, detailDTOS,esCountDTO);
|
|
|
} else if (childList.contains(field)) {
|
|
|
- this.getChildAnalysisDTOS(agg, field, detailDTOS);
|
|
|
+ if (CollectionUtils.isEmpty(values)) {
|
|
|
+ this.getChildCountDTOS(agg, field, detailDTOS);
|
|
|
+ } else {
|
|
|
+ this.getChildAnalysisDTOS(agg, field, detailDTOS, esCountDTO);
|
|
|
+ }
|
|
|
} else if (numberList.contains(field)) {
|
|
|
this.getNumberAnalysisDTOS(agg, field, detailDTOS);
|
|
|
} else {
|
|
@@ -812,23 +827,8 @@ public class EsCountService {
|
|
|
}
|
|
|
}
|
|
|
esCountDTO.setDetailDTOS(detailDTOS);
|
|
|
+ esCountDTO.setCondition(searchCondition);
|
|
|
return esCountDTO;
|
|
|
}
|
|
|
|
|
|
- public void getTermCountAnalysis(Aggregate agg, String field,String value,List<String> values, List<EsCountDetailDTO> detailDTOS) {
|
|
|
- List<StringTermsBucket> list = agg.sterms().buckets().array();
|
|
|
- list.forEach(bucket -> {
|
|
|
- EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
|
- dto.setField(field);
|
|
|
- Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
|
- dto.setName(bucket.key().stringValue());
|
|
|
- dto.setNumber(bucket.docCount());
|
|
|
- if (aggregate != null) {
|
|
|
- dto.setNumber(aggregate.filter().docCount());
|
|
|
- }
|
|
|
- if (dto.getNumber() > 0) {
|
|
|
- detailDTOS.add(dto);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
}
|