|
@@ -32,14 +32,17 @@ public class ChildCountAnalysisBuilder implements IEsCountAnalysisBuilder {
|
|
|
public Aggregation createCountAnalyseAgg() throws Exception {
|
|
|
Aggregation aggregation = null;
|
|
|
List<Query> queryList = new ArrayList<>();
|
|
|
+ Query q = null;
|
|
|
Query q1 = QueryBuilders.term(i -> i.field("custom_field.field").value(fieldId));
|
|
|
- if (projectId != null) {
|
|
|
- Query q2 = QueryBuilders.term(i -> i.field("custom_field.project_id").value(projectId));
|
|
|
- queryList.add(q2);
|
|
|
- }
|
|
|
if (taskId != null) {
|
|
|
Query q3 = QueryBuilders.term(i -> i.field("custom_field.task_id").value(taskId));
|
|
|
queryList.add(q3);
|
|
|
+ } else {
|
|
|
+ if (projectId != null) {
|
|
|
+ Query q2 = QueryBuilders.term(i -> i.field("custom_field.project_id").value(projectId));
|
|
|
+ queryList.add(q2);
|
|
|
+ q = QueryBuilders.exists(i -> i.field("custom_field.task_id"));
|
|
|
+ }
|
|
|
}
|
|
|
queryList.add(q1);
|
|
|
Aggregation termAgg = null;
|
|
@@ -59,10 +62,19 @@ public class ChildCountAnalysisBuilder implements IEsCountAnalysisBuilder {
|
|
|
queryList.add(query);
|
|
|
}
|
|
|
Aggregation terms = AggregationBuilders.terms(i -> i.field("custom_field.stats_value.raw").size(topN));
|
|
|
- termAgg = new Aggregation.Builder().filter(n -> n.bool(k -> k.must(queryList)))
|
|
|
- .aggregations(new HashMap() {{
|
|
|
- put("filterAgg", terms);
|
|
|
- }}).build();
|
|
|
+ if (taskId != null) {
|
|
|
+ termAgg = new Aggregation.Builder().filter(n -> n.bool(k -> k.must(queryList)))
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("filterAgg", terms);
|
|
|
+ }}).build();
|
|
|
+ } else {
|
|
|
+ Query finalQ = q;
|
|
|
+ termAgg = new Aggregation.Builder().filter(n -> n.bool(k -> k.must(queryList).mustNot(finalQ)))
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("filterAgg", terms);
|
|
|
+ }}).build();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
} else {
|
|
|
if (!CollectionUtils.isEmpty(values)) {
|
|
@@ -80,10 +92,18 @@ public class ChildCountAnalysisBuilder implements IEsCountAnalysisBuilder {
|
|
|
queryList.add(query);
|
|
|
}
|
|
|
Aggregation terms = AggregationBuilders.terms(i -> i.field("custom_field.field_value.raw").size(topN));
|
|
|
- termAgg = new Aggregation.Builder().filter(n -> n.bool(k -> k.must(queryList)))
|
|
|
- .aggregations(new HashMap() {{
|
|
|
- put("filterAgg", terms);
|
|
|
- }}).build();
|
|
|
+ if (taskId != null) {
|
|
|
+ termAgg = new Aggregation.Builder().filter(n -> n.bool(k -> k.must(queryList)))
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("filterAgg", terms);
|
|
|
+ }}).build();
|
|
|
+ } else {
|
|
|
+ Query finalQ = q;
|
|
|
+ termAgg = new Aggregation.Builder().filter(n -> n.bool(k -> k.must(queryList).mustNot(finalQ)))
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("filterAgg", terms);
|
|
|
+ }}).build();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|