public static Aggregations fromXContent(XContentParser parser) throws IOException { final List<Aggregation> aggregations = new ArrayList<>(); XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.START_OBJECT) { SetOnce<Aggregation> typedAgg = new SetOnce<>(); String currentField = parser.currentName(); parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, typedAgg::set); if (typedAgg.get() != null) { aggregations.add(typedAgg.get()); } else { throw new ParsingException(parser.getTokenLocation(), String.format(Locale.ROOT, "Could not parse aggregation keyed as [%s]", currentField)); } } } return new Aggregations(aggregations); } }
bucket.setAggregations(new Aggregations(aggregations)); return bucket;
static <B extends ParsedBucket> B parseTermsBucketXContent(final XContentParser parser, final Supplier<B> bucketSupplier, final CheckedBiConsumer<XContentParser, B, IOException> keyConsumer) throws IOException { final B bucket = bucketSupplier.get(); final List<Aggregation> aggregations = new ArrayList<>(); XContentParser.Token token; String currentFieldName = parser.currentName(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (CommonFields.KEY_AS_STRING.getPreferredName().equals(currentFieldName)) { bucket.setKeyAsString(parser.text()); } else if (CommonFields.KEY.getPreferredName().equals(currentFieldName)) { keyConsumer.accept(parser, bucket); } else if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) { bucket.setDocCount(parser.longValue()); } else if (DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME.getPreferredName().equals(currentFieldName)) { bucket.docCountError = parser.longValue(); bucket.showDocCountError = true; } } else if (token == XContentParser.Token.START_OBJECT) { XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, aggregations::add); } } bucket.setAggregations(new Aggregations(aggregations)); return bucket; } }
aggregation.aggregations = new Aggregations(aggregations); return aggregation;
bucket.setAggregations(new Aggregations(aggregations)); return bucket;
bucket.setAggregations(new Aggregations(aggregations)); return bucket;
bucket.setAggregations(new Aggregations(aggregations)); return bucket;
static ParsedBucket fromXContent(XContentParser parser, boolean keyed) throws IOException { final ParsedBucket bucket = new ParsedBucket(); bucket.setKeyed(keyed); XContentParser.Token token = parser.currentToken(); String currentFieldName = parser.currentName(); if (keyed) { ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation); bucket.key = currentFieldName; ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation); } List<Aggregation> aggregations = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) { bucket.setDocCount(parser.longValue()); } } else if (token == XContentParser.Token.START_OBJECT) { XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, aggregations::add); } } bucket.setAggregations(new Aggregations(aggregations)); return bucket; } }
public static Aggregations fromXContent(XContentParser parser) throws IOException { final List<Aggregation> aggregations = new ArrayList<>(); XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.START_OBJECT) { aggregations.add(XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class)); } } return new Aggregations(aggregations); } }
public static Aggregations fromXContent(XContentParser parser) throws IOException { final List<Aggregation> aggregations = new ArrayList<>(); XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.START_OBJECT) { SetOnce<Aggregation> typedAgg = new SetOnce<>(); String currentField = parser.currentName(); parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, typedAgg::set); if (typedAgg.get() != null) { aggregations.add(typedAgg.get()); } else { throw new ParsingException(parser.getTokenLocation(), String.format(Locale.ROOT, "Could not parse aggregation keyed as [%s]", currentField)); } } } return new Aggregations(aggregations); } }
public static Aggregations fromXContent(XContentParser parser) throws IOException { final List<Aggregation> aggregations = new ArrayList<>(); XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.START_OBJECT) { SetOnce<Aggregation> typedAgg = new SetOnce<>(); String currentField = parser.currentName(); parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, typedAgg::set); if (typedAgg.get() != null) { aggregations.add(typedAgg.get()); } else { throw new ParsingException(parser.getTokenLocation(), String.format(Locale.ROOT, "Could not parse aggregation keyed as [%s]", currentField)); } } } return new Aggregations(aggregations); } }
static <B extends ParsedBucket> B parseTermsBucketXContent(final XContentParser parser, final Supplier<B> bucketSupplier, final CheckedBiConsumer<XContentParser, B, IOException> keyConsumer) throws IOException { final B bucket = bucketSupplier.get(); final List<Aggregation> aggregations = new ArrayList<>(); XContentParser.Token token; String currentFieldName = parser.currentName(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (CommonFields.KEY_AS_STRING.getPreferredName().equals(currentFieldName)) { bucket.setKeyAsString(parser.text()); } else if (CommonFields.KEY.getPreferredName().equals(currentFieldName)) { keyConsumer.accept(parser, bucket); } else if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) { bucket.setDocCount(parser.longValue()); } else if (DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME.getPreferredName().equals(currentFieldName)) { bucket.docCountError = parser.longValue(); bucket.showDocCountError = true; } } else if (token == XContentParser.Token.START_OBJECT) { aggregations.add(XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class)); } } bucket.setAggregations(new Aggregations(aggregations)); return bucket; } }
static <B extends ParsedBucket> B parseSignificantTermsBucketXContent(final XContentParser parser, final B bucket, final CheckedBiConsumer<XContentParser, B, IOException> keyConsumer) throws IOException { final List<Aggregation> aggregations = new ArrayList<>(); XContentParser.Token token; String currentFieldName = parser.currentName(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (CommonFields.KEY_AS_STRING.getPreferredName().equals(currentFieldName)) { bucket.setKeyAsString(parser.text()); } else if (CommonFields.KEY.getPreferredName().equals(currentFieldName)) { keyConsumer.accept(parser, bucket); } else if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) { long value = parser.longValue(); bucket.subsetDf = value; bucket.setDocCount(value); } else if (InternalSignificantTerms.SCORE.equals(currentFieldName)) { bucket.score = parser.longValue(); } else if (InternalSignificantTerms.BG_COUNT.equals(currentFieldName)) { bucket.supersetDf = parser.longValue(); } } else if (token == XContentParser.Token.START_OBJECT) { aggregations.add(XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class)); } } bucket.setAggregations(new Aggregations(aggregations)); return bucket; } }
static <B extends ParsedBucket> B parseTermsBucketXContent(final XContentParser parser, final Supplier<B> bucketSupplier, final CheckedBiConsumer<XContentParser, B, IOException> keyConsumer) throws IOException { final B bucket = bucketSupplier.get(); final List<Aggregation> aggregations = new ArrayList<>(); XContentParser.Token token; String currentFieldName = parser.currentName(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (CommonFields.KEY_AS_STRING.getPreferredName().equals(currentFieldName)) { bucket.setKeyAsString(parser.text()); } else if (CommonFields.KEY.getPreferredName().equals(currentFieldName)) { keyConsumer.accept(parser, bucket); } else if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) { bucket.setDocCount(parser.longValue()); } else if (DOC_COUNT_ERROR_UPPER_BOUND_FIELD_NAME.getPreferredName().equals(currentFieldName)) { bucket.docCountError = parser.longValue(); bucket.showDocCountError = true; } } else if (token == XContentParser.Token.START_OBJECT) { XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, aggregations::add); } } bucket.setAggregations(new Aggregations(aggregations)); return bucket; } }
bucket.setAggregations(new Aggregations(aggregations)); return bucket;
protected static <T extends ParsedSingleBucketAggregation> T parseXContent(final XContentParser parser, T aggregation, String name) throws IOException { aggregation.setName(name); XContentParser.Token token = parser.currentToken(); String currentFieldName = parser.currentName(); if (token == XContentParser.Token.FIELD_NAME) { token = parser.nextToken(); } ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser::getTokenLocation); List<Aggregation> aggregations = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) { aggregation.setDocCount(parser.longValue()); } } else if (token == XContentParser.Token.START_OBJECT) { if (CommonFields.META.getPreferredName().equals(currentFieldName)) { aggregation.metadata = parser.map(); } else { aggregations.add(XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class)); } } } aggregation.aggregations = new Aggregations(aggregations); return aggregation; } }
aggregation.aggregations = new Aggregations(aggregations); return aggregation;
static ParsedBucket fromXContent(XContentParser parser, boolean keyed) throws IOException { final ParsedBucket bucket = new ParsedBucket(); bucket.setKeyed(keyed); XContentParser.Token token = parser.currentToken(); String currentFieldName = parser.currentName(); if (keyed) { ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation); bucket.key = currentFieldName; ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation); } List<Aggregation> aggregations = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) { bucket.setDocCount(parser.longValue()); } } else if (token == XContentParser.Token.START_OBJECT) { aggregations.add(XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class)); } } bucket.setAggregations(new Aggregations(aggregations)); return bucket; } }
static ParsedBucket fromXContent(XContentParser parser, boolean keyed) throws IOException { final ParsedBucket bucket = new ParsedBucket(); bucket.setKeyed(keyed); XContentParser.Token token = parser.currentToken(); String currentFieldName = parser.currentName(); if (keyed) { ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation); bucket.key = currentFieldName; ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation); } List<Aggregation> aggregations = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) { bucket.setDocCount(parser.longValue()); } } else if (token == XContentParser.Token.START_OBJECT) { XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, aggregations::add); } } bucket.setAggregations(new Aggregations(aggregations)); return bucket; } }
static ParsedBucket fromXContent(XContentParser parser, boolean keyed) throws IOException { final ParsedBucket bucket = new ParsedBucket(); bucket.setKeyed(keyed); XContentParser.Token token = parser.currentToken(); String currentFieldName = parser.currentName(); if (keyed) { ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser::getTokenLocation); bucket.key = currentFieldName; ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation); } List<Aggregation> aggregations = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (CommonFields.DOC_COUNT.getPreferredName().equals(currentFieldName)) { bucket.setDocCount(parser.longValue()); } } else if (token == XContentParser.Token.START_OBJECT) { XContentParserUtils.parseTypedKeysObject(parser, Aggregation.TYPED_KEYS_DELIMITER, Aggregation.class, aggregations::add); } } bucket.setAggregations(new Aggregations(aggregations)); return bucket; } }