|
@@ -19,7 +19,6 @@ import cn.cslg.pas.service.business.CommonService;
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
import co.elastic.clients.elasticsearch._types.aggregations.*;
|
|
import co.elastic.clients.elasticsearch._types.aggregations.*;
|
|
-import co.elastic.clients.elasticsearch._types.query_dsl.IdsQuery;
|
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
@@ -37,6 +36,7 @@ import java.io.IOException;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.atomic.AtomicLong;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -527,32 +527,43 @@ public class EsCountService {
|
|
EsCountDTO esCountDTO, String firstName,
|
|
EsCountDTO esCountDTO, String firstName,
|
|
Map<String, List<EsCountDetailDTO>> map,List<String> values) {
|
|
Map<String, List<EsCountDetailDTO>> map,List<String> values) {
|
|
List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
|
|
List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
|
|
|
|
+ long otherNum = 0l;
|
|
|
|
+ List<StringTermsBucket> list = agg.sterms().buckets().array();
|
|
|
|
+ for (StringTermsBucket bucket : list) {
|
|
|
|
+ EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
|
|
+ dto.setField(field);
|
|
|
|
+ Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
|
|
+ String value = bucket.key().stringValue();
|
|
|
|
+ if (StringUtils.isNotEmpty(value)) {
|
|
|
|
+ dto.setName(value);
|
|
|
|
+ dto.setNumber(bucket.docCount());
|
|
|
|
+ dto.setTopN(topN);
|
|
|
|
+ dto.setFirstName(firstName);
|
|
|
|
+ if (aggregate != null) {
|
|
|
|
+ dto.setNumber(aggregate.filter().docCount());
|
|
|
|
+ }
|
|
|
|
+ if (dto.getNumber() > 0) {
|
|
|
|
+ countDetailDTOS.add(dto);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ otherNum += 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (countDetailDTOS.size() > topN) {
|
|
|
|
+ countDetailDTOS.remove(countDetailDTOS.size() - 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
countDTO.setField(field);
|
|
countDTO.setField(field);
|
|
countDTO.setName("其他");
|
|
countDTO.setName("其他");
|
|
countDTO.setTopN(topN);
|
|
countDTO.setTopN(topN);
|
|
Long count = agg.sterms().sumOtherDocCount();
|
|
Long count = agg.sterms().sumOtherDocCount();
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
- countDTO.setNumber(count);
|
|
|
|
|
|
+ countDTO.setNumber(count + otherNum);
|
|
detailDTOS.add(countDTO);
|
|
detailDTOS.add(countDTO);
|
|
}
|
|
}
|
|
-
|
|
|
|
- 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());
|
|
|
|
- dto.setTopN(topN);
|
|
|
|
- dto.setFirstName(firstName);
|
|
|
|
- if (aggregate != null) {
|
|
|
|
- dto.setNumber(aggregate.filter().docCount());
|
|
|
|
- }
|
|
|
|
- if (dto.getNumber() > 0) {
|
|
|
|
- countDetailDTOS.add(dto);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ esCountDTO.setRemainingNum(count);
|
|
|
|
|
|
List<String> strs = new ArrayList<>();
|
|
List<String> strs = new ArrayList<>();
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
@@ -1035,18 +1046,9 @@ public class EsCountService {
|
|
Map<String, List<EsCountDetailDTO>> map, List<String> values) {
|
|
Map<String, List<EsCountDetailDTO>> map, List<String> values) {
|
|
Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
|
|
List<EsCountDetailDTO> countDetailDTOS = new ArrayList<>();
|
|
- EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
|
|
- countDTO.setField(field);
|
|
|
|
- countDTO.setName("其他");
|
|
|
|
- countDTO.setTopN(topN);
|
|
|
|
- Long count = termsAgg.sterms().sumOtherDocCount();
|
|
|
|
- if (count > 0) {
|
|
|
|
- countDTO.setNumber(count);
|
|
|
|
- countDetailDTOS.add(countDTO);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ long otherNum = 0l;
|
|
List<StringTermsBucket> list = termsAgg.sterms().buckets().array();
|
|
List<StringTermsBucket> list = termsAgg.sterms().buckets().array();
|
|
- list.forEach(bucket -> {
|
|
|
|
|
|
+ for (StringTermsBucket bucket : list) {
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
dto.setField(field);
|
|
dto.setField(field);
|
|
Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
Aggregate aggregate = bucket.aggregations().get("filter_agg");
|
|
@@ -1062,11 +1064,25 @@ public class EsCountService {
|
|
if (dto.getNumber() > 0) {
|
|
if (dto.getNumber() > 0) {
|
|
countDetailDTOS.add(dto);
|
|
countDetailDTOS.add(dto);
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ otherNum += 1;
|
|
}
|
|
}
|
|
-// if (dto.getNumber() > 0) {
|
|
|
|
-// detailDTOS.add(dto);
|
|
|
|
-// }
|
|
|
|
- });
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (countDetailDTOS.size() > topN) {
|
|
|
|
+ countDetailDTOS.remove(countDetailDTOS.size() - 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ EsCountDetailDTO countDTO = new EsCountDetailDTO();
|
|
|
|
+ countDTO.setField(field);
|
|
|
|
+ countDTO.setName("其他");
|
|
|
|
+ countDTO.setTopN(topN);
|
|
|
|
+ Long count = termsAgg.sterms().sumOtherDocCount();
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ countDTO.setNumber(count + otherNum);
|
|
|
|
+ countDetailDTOS.add(countDTO);
|
|
|
|
+ }
|
|
|
|
+ esCountDTO.setRemainingNum(count);
|
|
|
|
|
|
List<String> strs = new ArrayList<>();
|
|
List<String> strs = new ArrayList<>();
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
if (!CollectionUtils.isEmpty(values)) {
|