|
@@ -1,15 +1,13 @@
|
|
|
package cn.cslg.pas.factorys.EsCountAnalyseBuilderFactory;
|
|
|
|
|
|
import cn.cslg.pas.factorys.EsCountBuilderFactory.IEsCountBuilder;
|
|
|
-import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
|
|
|
-import co.elastic.clients.elasticsearch._types.aggregations.AggregationBuilders;
|
|
|
-import co.elastic.clients.elasticsearch._types.aggregations.ChildrenAggregation;
|
|
|
-import co.elastic.clients.elasticsearch._types.aggregations.TermsAggregation;
|
|
|
+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 co.elastic.clients.json.JsonData;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
@@ -32,7 +30,59 @@ public class ChildCountAnalysisBuilder implements IEsCountAnalysisBuilder {
|
|
|
@Override
|
|
|
public Aggregation createCountAnalyseAgg() throws Exception {
|
|
|
Aggregation aggregation = null;
|
|
|
-
|
|
|
+ List<Query> queryList = new ArrayList<>();
|
|
|
+ Query q1 = QueryBuilders.term(i -> i.field("custom_field.field").value(fieldId));
|
|
|
+// Query q2 = QueryBuilders.term(i -> i.field("custom_field.field_type").value(fieldType));
|
|
|
+ queryList.add(q1);
|
|
|
+// queryList.add(q2);
|
|
|
+ Aggregation termAgg = null;
|
|
|
+ if (ifHaveChild) {
|
|
|
+
|
|
|
+ Aggregation filterAgg = AggregationBuilders.filter(n -> n.bool(k -> k.must(queryList)));
|
|
|
+ termAgg = new Aggregation.Builder().terms(new TermsAggregation.Builder()
|
|
|
+ .field("custom_field.stats_value.raw").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("filterAgg", filterAgg);
|
|
|
+ }}).build();
|
|
|
+ } else {
|
|
|
+ if (!CollectionUtils.isEmpty(values)) {
|
|
|
+ termAgg = AggregationBuilders.terms(i -> i.field(field).include(j -> j.terms(values)).size(topN));
|
|
|
+ } else {
|
|
|
+ if (StringUtils.isNotEmpty(valueOne) && StringUtils.isEmpty(valueTwo)) {
|
|
|
+ String str = "*";
|
|
|
+ String s = str.concat(valueOne).concat("*");
|
|
|
+ Query query = QueryBuilders.wildcard(i -> i.field("custom_field.field_value.raw").value(s));
|
|
|
+ queryList.add(query);
|
|
|
+ } else if (StringUtils.isNotEmpty(valueOne) && StringUtils.isNotEmpty(valueTwo)) {
|
|
|
+ //日期/数字
|
|
|
+ String start = valueOne.substring(0, valueOne.indexOf("-"));
|
|
|
+ String end = valueOne.substring(valueOne.indexOf("-") + 1);
|
|
|
+ Query query = QueryBuilders.range(range -> range.field("custom_field.field_value.raw")
|
|
|
+ .gte(JsonData.of(start)).lte(JsonData.of(end)));
|
|
|
+ queryList.add(query);
|
|
|
+ }
|
|
|
+ Aggregation filterAgg = AggregationBuilders.filter(n -> n.bool(k -> k.must(queryList)));
|
|
|
+ termAgg = new Aggregation.Builder().terms(new TermsAggregation.Builder()
|
|
|
+ .field("custom_field.field_value.raw").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("filterAgg", filterAgg);
|
|
|
+ }}).build();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Aggregation finalTermAgg = termAgg;
|
|
|
+ Aggregation terms = new Aggregation.Builder().terms(new TermsAggregation.Builder()
|
|
|
+ .field(field).size(topN).build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("termAgg", finalTermAgg);
|
|
|
+ }}).build();
|
|
|
+
|
|
|
+
|
|
|
+ aggregation = new Aggregation.Builder().children(new ChildrenAggregation.Builder()
|
|
|
+ .type("project_customfield").build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("childAgg", terms);
|
|
|
+ }}).build();
|
|
|
return aggregation;
|
|
|
}
|
|
|
|