private AggregationBuilder updateAggIfNested(AggregationBuilder lastAgg, Field field) { if (field.isNested()) { lastAgg = AggregationBuilders.nested(field.getName() + "Nested",field.getNestedPath()) .subAggregation(lastAgg); } return lastAgg; }
/** * Create a new {@link Nested} aggregation with the given name. */ public static NestedAggregationBuilder nested(String name, String path) { return new NestedAggregationBuilder(name, path); }
private static AbstractAggregationBuilder createRangeFacet(String metricKey, Double... thresholds) { RangeAggregationBuilder rangeAgg = AggregationBuilders.range(metricKey) .field(FIELD_MEASURES_VALUE); final int lastIndex = thresholds.length - 1; IntStream.range(0, thresholds.length) .forEach(i -> { if (i == 0) { rangeAgg.addUnboundedTo(thresholds[0]); rangeAgg.addRange(thresholds[0], thresholds[1]); } else if (i == lastIndex) { rangeAgg.addUnboundedFrom(thresholds[lastIndex]); } else { rangeAgg.addRange(thresholds[i], thresholds[i + 1]); } }); return AggregationBuilders.nested("nested_" + metricKey, FIELD_MEASURES) .subAggregation( AggregationBuilders.filter("filter_" + metricKey, termsQuery(FIELD_MEASURES_KEY, metricKey)) .subAggregation(rangeAgg)); }
@Override protected AggregationBuilder shallowCopy(Builder factoriesBuilder, Map<String, Object> metaData) { return new NestedAggregationBuilder(this, factoriesBuilder, metaData); }
.order(Terms.Order.count(false))); request.addAggregation(AggregationBuilders.nested(FIELD_NCLOC_LANGUAGE_DISTRIBUTION, FIELD_NCLOC_LANGUAGE_DISTRIBUTION) .subAggregation(AggregationBuilders.terms(FIELD_NCLOC_LANGUAGE_DISTRIBUTION + "_terms") .field(FIELD_DISTRIB_LANGUAGE) .size(MAX_PAGE_SIZE) .subAggregation(AggregationBuilders.filter(NCLOC_KEY + "_filter", termQuery(FIELD_MEASURES_KEY, NCLOC_KEY)) .subAggregation(sum(NCLOC_KEY + "_filter_sum").field(FIELD_MEASURES_VALUE))));
/** * Create a new {@link Nested} aggregation with the given name. */ public static NestedAggregationBuilder nested(String name, String path) { return new NestedAggregationBuilder(name, path); }
private static AbstractAggregationBuilder createRatingFacet(String metricKey) { return AggregationBuilders.nested("nested_" + metricKey, FIELD_MEASURES) .subAggregation( AggregationBuilders.filter("filter_" + metricKey, termsQuery(FIELD_MEASURES_KEY, metricKey)) .subAggregation(filters(metricKey, new KeyedFilter("1", termQuery(FIELD_MEASURES_VALUE, 1d)), new KeyedFilter("2", termQuery(FIELD_MEASURES_VALUE, 2d)), new KeyedFilter("3", termQuery(FIELD_MEASURES_VALUE, 3d)), new KeyedFilter("4", termQuery(FIELD_MEASURES_VALUE, 4d)), new KeyedFilter("5", termQuery(FIELD_MEASURES_VALUE, 5d))))); }
/** * Create a new {@link Nested} aggregation with the given name. */ public static NestedAggregationBuilder nested(String name, String path) { return new NestedAggregationBuilder(name, path); }
private AggregationBuilder updateAggIfNested(AggregationBuilder lastAgg, Field field) { if (field.isNested()) { lastAgg = AggregationBuilders.nested(field.getName() + "Nested",field.getNestedPath()) .subAggregation(lastAgg); } return lastAgg; }
/** * Create a new {@link Nested} aggregation with the given name. */ public static NestedAggregationBuilder nested(String name, String path) { return new NestedAggregationBuilder(name, path); }
private static AbstractAggregationBuilder createRangeFacet(String metricKey, Double... thresholds) { RangeAggregationBuilder rangeAgg = AggregationBuilders.range(metricKey) .field(FIELD_MEASURES_VALUE); final int lastIndex = thresholds.length - 1; IntStream.range(0, thresholds.length) .forEach(i -> { if (i == 0) { rangeAgg.addUnboundedTo(thresholds[0]); rangeAgg.addRange(thresholds[0], thresholds[1]); } else if (i == lastIndex) { rangeAgg.addUnboundedFrom(thresholds[lastIndex]); } else { rangeAgg.addRange(thresholds[i], thresholds[i + 1]); } }); return AggregationBuilders.nested("nested_" + metricKey, FIELD_MEASURES) .subAggregation( AggregationBuilders.filter("filter_" + metricKey, termsQuery(FIELD_MEASURES_KEY, metricKey)) .subAggregation(rangeAgg)); }
@Override protected AggregationBuilder shallowCopy(Builder factoriesBuilder, Map<String, Object> metaData) { return new NestedAggregationBuilder(this, factoriesBuilder, metaData); }
/** * 增加属性的聚合 * * @param nativeSearchQueryBuilder 查询主体 */ private void addAttributeAggregation(NativeSearchQueryBuilder nativeSearchQueryBuilder) { nativeSearchQueryBuilder.addAggregation(AggregationBuilders.nested("esAttributes", "esAttributes").subAggregation(AggregationBuilders.terms("attributeName").field("esAttributes.attributeName").subAggregation(AggregationBuilders.terms("attributeValue").field("esAttributes.attributeValue")))); }
@Override protected AggregationBuilder shallowCopy(Builder factoriesBuilder, Map<String, Object> metaData) { return new NestedAggregationBuilder(this, factoriesBuilder, metaData); }
.order(Terms.Order.count(false))); request.addAggregation(AggregationBuilders.nested(FIELD_NCLOC_LANGUAGE_DISTRIBUTION, FIELD_NCLOC_LANGUAGE_DISTRIBUTION) .subAggregation(AggregationBuilders.terms(FIELD_NCLOC_LANGUAGE_DISTRIBUTION + "_terms") .field(FIELD_DISTRIB_LANGUAGE) .size(MAX_PAGE_SIZE) .subAggregation(AggregationBuilders.filter(NCLOC_KEY + "_filter", termQuery(FIELD_MEASURES_KEY, NCLOC_KEY)) .subAggregation(sum(NCLOC_KEY + "_filter_sum").field(FIELD_MEASURES_VALUE))));
public static NestedAggregationBuilder parse(String aggregationName, XContentParser parser) throws IOException { String path = null; XContentParser.Token token; String currentFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { if (NestedAggregator.PATH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { path = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); } } else { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + aggregationName + "]."); } } if (path == null) { // "field" doesn't exist, so we fall back to the context of the ancestors throw new ParsingException(parser.getTokenLocation(), "Missing [path] field for nested aggregation [" + aggregationName + "]"); } return new NestedAggregationBuilder(aggregationName, path); }
private static AbstractAggregationBuilder createRatingFacet(String metricKey) { return AggregationBuilders.nested("nested_" + metricKey, FIELD_MEASURES) .subAggregation( AggregationBuilders.filter("filter_" + metricKey, termsQuery(FIELD_MEASURES_KEY, metricKey)) .subAggregation(filters(metricKey, new KeyedFilter("1", termQuery(FIELD_MEASURES_VALUE, 1d)), new KeyedFilter("2", termQuery(FIELD_MEASURES_VALUE, 2d)), new KeyedFilter("3", termQuery(FIELD_MEASURES_VALUE, 3d)), new KeyedFilter("4", termQuery(FIELD_MEASURES_VALUE, 4d)), new KeyedFilter("5", termQuery(FIELD_MEASURES_VALUE, 5d))))); }
public static NestedAggregationBuilder parse(String aggregationName, XContentParser parser) throws IOException { String path = null; XContentParser.Token token; String currentFieldName = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { if (NestedAggregator.PATH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { path = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); } } else { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + aggregationName + "]."); } } if (path == null) { // "field" doesn't exist, so we fall back to the context of the ancestors throw new ParsingException(parser.getTokenLocation(), "Missing [path] field for nested aggregation [" + aggregationName + "]"); } return new NestedAggregationBuilder(aggregationName, path); }
searchRequestBuilder.addAggregation(AggregationBuilders.nested(TAG_FACET_AGGS, NESTED_BDEFTAGS_PATH).subAggregation( AggregationBuilders.terms(TAGTYPE_CODE_AGGREGATION).field(BDEF_TAGTYPE_CODE_FIELD).subAggregation( AggregationBuilders.terms(TAGTYPE_NAME_AGGREGATION).field(BDEF_TAGTYPE_NAME_FIELD).subAggregation(
public static NestedAggregationBuilder parse(String aggregationName, QueryParseContext context) throws IOException { String path = null; XContentParser.Token token; String currentFieldName = null; XContentParser parser = context.parser(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { if (NestedAggregator.PATH_FIELD.match(currentFieldName)) { path = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); } } else { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + aggregationName + "]."); } } if (path == null) { // "field" doesn't exist, so we fall back to the context of the ancestors throw new ParsingException(parser.getTokenLocation(), "Missing [path] field for nested aggregation [" + aggregationName + "]"); } return new NestedAggregationBuilder(aggregationName, path); }