private boolean insertFilterIfExistsAfter(AggregationBuilder agg, List<Field> groupBy, AggregationBuilder builder, int nextPosition) throws SqlParseException { if (groupBy.size() <= nextPosition) return false; Field filterFieldCandidate = groupBy.get(nextPosition); if (!(filterFieldCandidate instanceof MethodField)) return false; MethodField methodField = (MethodField) filterFieldCandidate; if (!methodField.getName().toLowerCase().equals("filter")) return false; builder.subAggregation(aggMaker.makeGroupAgg(filterFieldCandidate).subAggregation(agg)); return true; }
private AggregationBuilder wrapNestedIfNeeded(AggregationBuilder nestedBuilder, boolean reverseNested) { if (!reverseNested) return nestedBuilder; if (reverseNested && !(nestedBuilder instanceof NestedAggregationBuilder)) return nestedBuilder; //we need to jump back to root return AggregationBuilders.reverseNested(nestedBuilder.getName() + "_REVERSED").subAggregation(nestedBuilder); }
public final AggregationBuilder rewrite(QueryRewriteContext context) throws IOException { AggregationBuilder rewritten = doRewrite(context); AggregatorFactories.Builder rewrittenSubAggs = factoriesBuilder.rewrite(context); if (rewritten != this) { return rewritten.setMetaData(getMetaData()).subAggregations(rewrittenSubAggs); } else if (rewrittenSubAggs != factoriesBuilder) { return shallowCopy(rewrittenSubAggs, getMetaData()); } else { return this; } }
AggregationBuilder ab = sr.source().aggregations().getAggregatorFactories().iterator().next(); if( ab instanceof TermsAggregationBuilder && "terms".equals(ab.getType()) && "indices".equals(ab.getName())) { if("_index".equals(((TermsAggregationBuilder) ab).field()) && ab.getPipelineAggregations().isEmpty() && ab.getSubAggregations().isEmpty()) {
@Override public final XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(getName()); if (this.metaData != null) { builder.field("meta", this.metaData); } builder.field(type); internalXContent(builder, params); if (aggregations != null || aggregationsBinary != null) { if (aggregations != null) { builder.startObject("aggregations"); for (AbstractAggregationBuilder subAgg : aggregations) { subAgg.toXContent(builder, params); } builder.endObject(); } if (aggregationsBinary != null) { if (XContentFactory.xContentType(aggregationsBinary) == builder.contentType()) { builder.rawField("aggregations", aggregationsBinary); } else { builder.field("aggregations_binary", aggregationsBinary); } } } return builder.endObject(); }
public AggregatorFactories build(SearchContext context, AggregatorFactory<?> parent) throws IOException { if (aggregationBuilders.isEmpty() && pipelineAggregatorBuilders.isEmpty()) { return EMPTY; } List<PipelineAggregationBuilder> orderedpipelineAggregators = null; if (skipResolveOrder) { orderedpipelineAggregators = new ArrayList<>(pipelineAggregatorBuilders); } else { orderedpipelineAggregators = resolvePipelineAggregatorOrder(this.pipelineAggregatorBuilders, this.aggregationBuilders, parent); } AggregatorFactory<?>[] aggFactories = new AggregatorFactory<?>[aggregationBuilders.size()]; int i = 0; for (AggregationBuilder agg : aggregationBuilders) { aggFactories[i] = agg.build(context, parent); ++i; } return new AggregatorFactories(parent, aggFactories, orderedpipelineAggregators); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (aggregationBuilders != null) { for (AggregationBuilder subAgg : aggregationBuilders) { subAgg.toXContent(builder, params); } } if (pipelineAggregatorBuilders != null) { for (PipelineAggregationBuilder subAgg : pipelineAggregatorBuilders) { subAgg.toXContent(builder, params); } } builder.endObject(); return builder; }
/** * Rewrites the given aggregation into its primitive form. Aggregations that for instance fetch resources from remote hosts or * can simplify / optimize itself should do their heavy lifting during {@link #rewrite(QueryRewriteContext)}. This method * rewrites the aggregation until it doesn't change anymore. * @throws IOException if an {@link IOException} occurs */ static AggregationBuilder rewriteAggregation(AggregationBuilder original, QueryRewriteContext context) throws IOException { AggregationBuilder builder = original; for (AggregationBuilder rewrittenBuilder = builder.rewrite(context); rewrittenBuilder != builder; rewrittenBuilder = builder.rewrite(context)) { builder = rewrittenBuilder; } return builder; }
AggregationBuilder ab = sr.source().aggregations().getAggregatorFactories().iterator().next(); if( ab instanceof TermsAggregationBuilder && "terms".equals(ab.getType()) && "indices".equals(ab.getName())) { if("_index".equals(((TermsAggregationBuilder) ab).field()) && ab.getPipelineAggregations().isEmpty() && ab.getSubAggregations().isEmpty()) {
public AggregatorFactories build(SearchContext context, AggregatorFactory<?> parent) throws IOException { if (aggregationBuilders.isEmpty() && pipelineAggregatorBuilders.isEmpty()) { return EMPTY; } List<PipelineAggregationBuilder> orderedpipelineAggregators = null; if (skipResolveOrder) { orderedpipelineAggregators = new ArrayList<>(pipelineAggregatorBuilders); } else { orderedpipelineAggregators = resolvePipelineAggregatorOrder(this.pipelineAggregatorBuilders, this.aggregationBuilders); } AggregatorFactory<?>[] aggFactories = new AggregatorFactory<?>[aggregationBuilders.size()]; for (int i = 0; i < aggregationBuilders.size(); i++) { aggFactories[i] = aggregationBuilders.get(i).build(context, parent); } return new AggregatorFactories(parent, aggFactories, orderedpipelineAggregators); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (aggregationBuilders != null) { for (AggregationBuilder subAgg : aggregationBuilders) { subAgg.toXContent(builder, params); } } if (pipelineAggregatorBuilders != null) { for (PipelineAggregationBuilder subAgg : pipelineAggregatorBuilders) { subAgg.toXContent(builder, params); } } builder.endObject(); return builder; }
/** * Rewrites the given aggregation into its primitive form. Aggregations that for instance fetch resources from remote hosts or * can simplify / optimize itself should do their heavy lifting during {@link #rewrite(QueryRewriteContext)}. This method * rewrites the aggregation until it doesn't change anymore. * @throws IOException if an {@link IOException} occurs */ static AggregationBuilder rewriteAggregation(AggregationBuilder original, QueryRewriteContext context) throws IOException { AggregationBuilder builder = original; for (AggregationBuilder rewrittenBuilder = builder.rewrite(context); rewrittenBuilder != builder; rewrittenBuilder = builder.rewrite(context)) { builder = rewrittenBuilder; } return builder; }
private static AggregationBuilder addEffortAggregationIfNeeded(IssueQuery query, AggregationBuilder aggregation) { if (hasQueryEffortFacet(query)) { aggregation.subAggregation(EFFORT_AGGREGATION); } return aggregation; }
@Override public void doValidate(AggregatorFactory<?> parent, Collection<AggregationBuilder> aggBuilders, Collection<PipelineAggregationBuilder> pipelineAggregatorFactories) { if (bucketsPaths.length != 1) { throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + " must contain a single entry for aggregation [" + name + "]"); } // Need to find the first agg name in the buckets path to check its a // multi bucket agg: aggs are split with '>' and can optionally have a // metric name after them by using '.' so need to split on both to get // just the agg name final String firstAgg = bucketsPaths[0].split("[>\\.]")[0]; Optional<AggregationBuilder> aggBuilder = aggBuilders.stream().filter((builder) -> builder.getName().equals(firstAgg)) .findAny(); if (aggBuilder.isPresent()) { if ((aggBuilder.get() instanceof MultiBucketAggregationBuilder) == false) { throw new IllegalArgumentException("The first aggregation in " + PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + " must be a multi-bucket aggregation for aggregation [" + name + "] found :" + aggBuilder.get().getClass().getName() + " for buckets path: " + bucketsPaths[0]); } } else { throw new IllegalArgumentException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName() + " aggregation does not exist for aggregation [" + name + "]: " + bucketsPaths[0]); } }
public final AggregationBuilder rewrite(QueryRewriteContext context) throws IOException { AggregationBuilder rewritten = doRewrite(context); AggregatorFactories.Builder rewrittenSubAggs = factoriesBuilder.rewrite(context); if (rewritten != this) { return rewritten.setMetaData(getMetaData()).subAggregations(rewrittenSubAggs); } else if (rewrittenSubAggs != factoriesBuilder) { return shallowCopy(rewrittenSubAggs, getMetaData()); } else { return this; } }
public AggregatorFactories build(SearchContext context, AggregatorFactory<?> parent) throws IOException { if (aggregationBuilders.isEmpty() && pipelineAggregatorBuilders.isEmpty()) { return EMPTY; } List<PipelineAggregationBuilder> orderedpipelineAggregators = null; if (skipResolveOrder) { orderedpipelineAggregators = new ArrayList<>(pipelineAggregatorBuilders); } else { orderedpipelineAggregators = resolvePipelineAggregatorOrder(this.pipelineAggregatorBuilders, this.aggregationBuilders, parent); } AggregatorFactory<?>[] aggFactories = new AggregatorFactory<?>[aggregationBuilders.size()]; for (int i = 0; i < aggregationBuilders.size(); i++) { aggFactories[i] = aggregationBuilders.get(i).build(context, parent); } return new AggregatorFactories(parent, aggFactories, orderedpipelineAggregators); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (aggregationBuilders != null) { for (AggregationBuilder subAgg : aggregationBuilders) { subAgg.toXContent(builder, params); } } if (pipelineAggregatorBuilders != null) { for (PipelineAggregationBuilder subAgg : pipelineAggregatorBuilders) { subAgg.toXContent(builder, params); } } builder.endObject(); return builder; }
/** * Rewrites the given aggregation into its primitive form. Aggregations that for instance fetch resources from remote hosts or * can simplify / optimize itself should do their heavy lifting during {@link #rewrite(QueryRewriteContext)}. This method * rewrites the aggregation until it doesn't change anymore. * @throws IOException if an {@link IOException} occurs */ static AggregationBuilder rewriteAggregation(AggregationBuilder original, QueryRewriteContext context) throws IOException { AggregationBuilder builder = original; for (AggregationBuilder rewrittenBuilder = builder.rewrite(context); rewrittenBuilder != builder; rewrittenBuilder = builder.rewrite(context)) { builder = rewrittenBuilder; } return builder; }
private static AggregationBuilder addSecurityReportSubAggregations(AggregationBuilder categoriesAggs, boolean includeCwe) { AggregationBuilder aggregationBuilder = addSecurityReportIssueCountAggregations(categoriesAggs); if (includeCwe) { categoriesAggs .subAggregation(addSecurityReportIssueCountAggregations(AggregationBuilders.terms("cwe").field(FIELD_ISSUE_CWE))); } return aggregationBuilder; }
/** * For backwards compatibility make an AggregateDefinition. */ protected static AggregateDefinition makeDefinition(AggregationBuilder nativeAggregation) { AggregateDescriptor descriptor = new AggregateDescriptor(); descriptor.setId(nativeAggregation.getName()); return descriptor; }