|
@@ -1,9 +1,16 @@
|
|
package cn.cslg.pas.factorys.EsCountAnalyseBuilderFactory;
|
|
package cn.cslg.pas.factorys.EsCountAnalyseBuilderFactory;
|
|
|
|
|
|
|
|
+import cn.cslg.pas.common.utils.StringUtils;
|
|
import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
|
|
import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
|
|
|
|
+import co.elastic.clients.elasticsearch._types.aggregations.AggregationBuilders;
|
|
|
|
+import co.elastic.clients.elasticsearch._types.aggregations.TermsAggregation;
|
|
|
|
+import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
|
|
+import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@Component
|
|
@Component
|
|
@@ -20,8 +27,23 @@ public class TermsCountAnalysisBuilder implements IEsCountAnalysisBuilder {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Aggregation createCountAnalyseAgg() throws Exception {
|
|
public Aggregation createCountAnalyseAgg() throws Exception {
|
|
-
|
|
|
|
- return null;
|
|
|
|
|
|
+ Aggregation aggregation = null;
|
|
|
|
+ if (StringUtils.isNotEmpty(valueOne)) {
|
|
|
|
+ String str = "*";
|
|
|
|
+ String s = str.concat(valueOne).concat("*");
|
|
|
|
+ Query query = QueryBuilders.wildcard(i -> i.field(field).value(s));
|
|
|
|
+ Aggregation filter = AggregationBuilders.filter(n -> n.bool(k -> k.must(query)));
|
|
|
|
+ aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
|
|
|
|
+ .field(field).size(topN).build())
|
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
|
+ put("filter_agg", filter);
|
|
|
|
+ }}).build();
|
|
|
|
+ } else if (CollectionUtils.isEmpty(values)) {
|
|
|
|
+ aggregation = AggregationBuilders.terms(i -> i.field(field).include(j -> j.terms(values)).size(topN));
|
|
|
|
+ } else {
|
|
|
|
+ aggregation = AggregationBuilders.terms(i -> i.field(field).size(topN));
|
|
|
|
+ }
|
|
|
|
+ return aggregation;
|
|
}
|
|
}
|
|
|
|
|
|
public String getField() {
|
|
public String getField() {
|