Explorar o código

子文档统计

zero hai 1 ano
pai
achega
56fbd722ef

+ 2 - 0
src/main/java/cn/cslg/pas/factorys/EsCountBuilderFactory/ChildCountBuilder.java

@@ -4,9 +4,11 @@ import co.elastic.clients.elasticsearch._types.aggregations.*;
 import co.elastic.clients.elasticsearch._types.query_dsl.Query;
 import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Component;
 
 import java.util.HashMap;
 
+@Component
 public class ChildCountBuilder implements IEsCountBuilder{
     public String field = "";
     public String valueOne = "";

+ 17 - 1
src/main/java/cn/cslg/pas/service/business/es/EsCountService.java

@@ -29,7 +29,7 @@ import java.util.stream.Collectors;
 @Service
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class EsCountService {
-    private final List<String> termList = Arrays.asList();
+    private final List<String> childList = Arrays.asList("childRaw");
     private final List<String> nestedList = Arrays.asList("PA", "IN", "PE");
     private final List<String> dateList = Arrays.asList("PD", "AD");
 
@@ -112,6 +112,22 @@ public class EsCountService {
                         detailDTOS.add(dto);
                     }
                 });
+            } else if (childList.contains(field)) {
+                Aggregate childAgg = agg.children().aggregations().get("child_agg");
+                List<StringTermsBucket> list = childAgg.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);
+                    }
+                });
             } else {
                 List<StringTermsBucket> list = agg.sterms().buckets().array();
                 list.forEach(bucket -> {