Add parsing for single bucket aggregations (#24564)

This adds parsing to all implementations of SingleBucketAggregations. They are mostly similar, so they share the common
base class `ParsedSingleBucketAggregation` and the shared base test `InternalSingleBucketAggregationTestCase`.
This commit is contained in:
Christoph Büscher 2017-05-11 11:50:35 +02:00 committed by GitHub
parent 570390ac36
commit c4fc8edc03
20 changed files with 471 additions and 5 deletions

View File

@ -41,7 +41,7 @@ public abstract class ParsedAggregation implements Aggregation, ToXContent {
}
private String name;
Map<String, Object> metadata;
protected Map<String, Object> metadata;
@Override
public final String getName() {

View File

@ -0,0 +1,93 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.bucket;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParserUtils;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
/**
* A base class for all the single bucket aggregations.
*/
public abstract class ParsedSingleBucketAggregation extends ParsedAggregation implements SingleBucketAggregation {
private long docCount;
protected Aggregations aggregations = new Aggregations(Collections.emptyList());
@Override
public long getDocCount() {
return docCount;
}
protected void setDocCount(long docCount) {
this.docCount = docCount;
}
@Override
public Aggregations getAggregations() {
return aggregations;
}
@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field(CommonFields.DOC_COUNT.getPreferredName(), docCount);
aggregations.toXContentInternal(builder, params);
return builder;
}
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;
}
}

View File

@ -0,0 +1,36 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.bucket.children;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import java.io.IOException;
public class ParsedChildren extends ParsedSingleBucketAggregation implements Children {
@Override
public String getType() {
return ChildrenAggregationBuilder.NAME;
}
public static ParsedChildren fromXContent(XContentParser parser, final String name) throws IOException {
return parseXContent(parser, new ParsedChildren(), name);
}
}

View File

@ -0,0 +1,36 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.bucket.filter;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import java.io.IOException;
public class ParsedFilter extends ParsedSingleBucketAggregation implements Filter {
@Override
public String getType() {
return FilterAggregationBuilder.NAME;
}
public static ParsedFilter fromXContent(XContentParser parser, final String name) throws IOException {
return parseXContent(parser, new ParsedFilter(), name);
}
}

View File

@ -0,0 +1,36 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.bucket.global;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import java.io.IOException;
public class ParsedGlobal extends ParsedSingleBucketAggregation implements Global {
@Override
public String getType() {
return GlobalAggregationBuilder.NAME;
}
public static ParsedGlobal fromXContent(XContentParser parser, final String name) throws IOException {
return parseXContent(parser, new ParsedGlobal(), name);
}
}

View File

@ -0,0 +1,36 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.bucket.missing;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import java.io.IOException;
public class ParsedMissing extends ParsedSingleBucketAggregation implements Missing {
@Override
public String getType() {
return MissingAggregationBuilder.NAME;
}
public static ParsedMissing fromXContent(XContentParser parser, final String name) throws IOException {
return parseXContent(parser, new ParsedMissing(), name);
}
}

View File

@ -0,0 +1,36 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.bucket.nested;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import java.io.IOException;
public class ParsedNested extends ParsedSingleBucketAggregation implements Nested {
@Override
public String getType() {
return NestedAggregationBuilder.NAME;
}
public static ParsedNested fromXContent(XContentParser parser, final String name) throws IOException {
return parseXContent(parser, new ParsedNested(), name);
}
}

View File

@ -0,0 +1,36 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.bucket.nested;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import java.io.IOException;
public class ParsedReverseNested extends ParsedSingleBucketAggregation implements Nested {
@Override
public String getType() {
return ReverseNestedAggregationBuilder.NAME;
}
public static ParsedReverseNested fromXContent(XContentParser parser, final String name) throws IOException {
return parseXContent(parser, new ParsedReverseNested(), name);
}
}

View File

@ -49,7 +49,7 @@ public class InternalSampler extends InternalSingleBucketAggregation implements
@Override
public String getType() {
return "sampler";
return NAME;
}
@Override

View File

@ -0,0 +1,36 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.bucket.sampler;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import java.io.IOException;
public class ParsedSampler extends ParsedSingleBucketAggregation implements Sampler {
@Override
public String getType() {
return InternalSampler.NAME;
}
public static ParsedSampler fromXContent(XContentParser parser, final String name) throws IOException {
return parseXContent(parser, new ParsedSampler(), name);
}
}

View File

@ -27,8 +27,15 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.children.InternalChildrenTests;
import org.elasticsearch.search.aggregations.bucket.filter.InternalFilterTests;
import org.elasticsearch.search.aggregations.bucket.global.InternalGlobalTests;
import org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogramTests;
import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogramTests;
import org.elasticsearch.search.aggregations.bucket.missing.InternalMissingTests;
import org.elasticsearch.search.aggregations.bucket.nested.InternalNestedTests;
import org.elasticsearch.search.aggregations.bucket.nested.InternalReverseNestedTests;
import org.elasticsearch.search.aggregations.bucket.sampler.InternalSamplerTests;
import org.elasticsearch.search.aggregations.bucket.terms.DoubleTermsTests;
import org.elasticsearch.search.aggregations.bucket.terms.LongTermsTests;
import org.elasticsearch.search.aggregations.bucket.terms.StringTermsTests;
@ -103,6 +110,13 @@ public class AggregationsTests extends ESTestCase {
aggsTests.add(new LongTermsTests());
aggsTests.add(new DoubleTermsTests());
aggsTests.add(new StringTermsTests());
aggsTests.add(new InternalMissingTests());
aggsTests.add(new InternalNestedTests());
aggsTests.add(new InternalReverseNestedTests());
aggsTests.add(new InternalChildrenTests());
aggsTests.add(new InternalGlobalTests());
aggsTests.add(new InternalFilterTests());
aggsTests.add(new InternalSamplerTests());
return Collections.unmodifiableList(aggsTests);
}

View File

@ -19,32 +19,45 @@
package org.elasticsearch.search.aggregations.bucket;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.search.aggregations.metrics.max.InternalMax;
import org.elasticsearch.search.aggregations.metrics.min.InternalMin;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.test.InternalAggregationTestCase;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.common.xcontent.XContentHelper.toXContent;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent;
public abstract class InternalSingleBucketAggregationTestCase<T extends InternalSingleBucketAggregation>
extends InternalAggregationTestCase<T> {
private final boolean hasInternalMax = randomBoolean();
private final boolean hasInternalMin = randomBoolean();
private boolean hasInternalMax;
private boolean hasInternalMin;
public Supplier<InternalAggregations> subAggregationsSupplier;
@Override
public void setUp() throws Exception {
super.setUp();
hasInternalMax = randomBoolean();
hasInternalMin = randomBoolean();
subAggregationsSupplier = () -> {
List<InternalAggregation> aggs = new ArrayList<>();
if (hasInternalMax) {
@ -89,4 +102,38 @@ public abstract class InternalSingleBucketAggregationTestCase<T extends Internal
}
extraAssertReduced(reduced, inputs);
}
@Override
protected void assertFromXContent(T aggregation, ParsedAggregation parsedAggregation) throws IOException {
assertTrue(parsedAggregation instanceof ParsedSingleBucketAggregation);
ParsedSingleBucketAggregation parsed = (ParsedSingleBucketAggregation) parsedAggregation;
assertEquals(aggregation.getDocCount(), parsed.getDocCount());
InternalAggregations aggregations = aggregation.getAggregations();
Map<String, Aggregation> expectedAggregations = new HashMap<>();
int expectedNumberOfAggregations = 0;
for (Aggregation expectedAggregation : aggregations) {
// since we shuffle xContent, we cannot rely on the order of the original inner aggregations for comparison
assertTrue(expectedAggregation instanceof InternalAggregation);
expectedAggregations.put(expectedAggregation.getName(), expectedAggregation);
expectedNumberOfAggregations++;
}
int parsedNumberOfAggregations = 0;
for (Aggregation parsedAgg : parsed.getAggregations()) {
assertTrue(parsedAgg instanceof ParsedAggregation);
assertTrue(expectedAggregations.keySet().contains(parsedAgg.getName()));
Aggregation expectedInternalAggregation = expectedAggregations.get(parsedAgg.getName());
final XContentType xContentType = randomFrom(XContentType.values());
final ToXContent.Params params = new ToXContent.MapParams(singletonMap(RestSearchAction.TYPED_KEYS_PARAM, "true"));
BytesReference expectedBytes = toXContent(expectedInternalAggregation, xContentType, params, false);
BytesReference actualBytes = toXContent(parsedAgg, xContentType, params, false);
assertToXContentEquivalent(expectedBytes, actualBytes, xContentType);
parsedNumberOfAggregations++;
}
assertEquals(expectedNumberOfAggregations, parsedNumberOfAggregations);
Class<? extends ParsedSingleBucketAggregation> parsedClass = implementationClass();
assertTrue(parsedClass != null && parsedClass.isInstance(parsedAggregation));
}
protected abstract Class<? extends ParsedSingleBucketAggregation> implementationClass();
}

View File

@ -22,6 +22,7 @@ package org.elasticsearch.search.aggregations.bucket.children;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import java.util.List;
@ -44,4 +45,8 @@ public class InternalChildrenTests extends InternalSingleBucketAggregationTestCa
return InternalChildren::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedChildren.class;
}
}

View File

@ -22,6 +22,7 @@ package org.elasticsearch.search.aggregations.bucket.filter;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import java.util.List;
@ -43,4 +44,9 @@ public class InternalFilterTests extends InternalSingleBucketAggregationTestCase
protected Reader<InternalFilter> instanceReader() {
return InternalFilter::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedFilter.class;
}
}

View File

@ -22,6 +22,7 @@ package org.elasticsearch.search.aggregations.bucket.global;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import java.util.List;
@ -44,4 +45,8 @@ public class InternalGlobalTests extends InternalSingleBucketAggregationTestCase
return InternalGlobal::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedGlobal.class;
}
}

View File

@ -22,6 +22,7 @@ package org.elasticsearch.search.aggregations.bucket.missing;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import java.util.List;
@ -44,4 +45,8 @@ public class InternalMissingTests extends InternalSingleBucketAggregationTestCas
return InternalMissing::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedMissing.class;
}
}

View File

@ -22,6 +22,7 @@ package org.elasticsearch.search.aggregations.bucket.nested;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import java.util.List;
@ -43,4 +44,9 @@ public class InternalNestedTests extends InternalSingleBucketAggregationTestCase
protected Reader<InternalNested> instanceReader() {
return InternalNested::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedNested.class;
}
}

View File

@ -22,6 +22,7 @@ package org.elasticsearch.search.aggregations.bucket.nested;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import java.util.List;
@ -43,4 +44,9 @@ public class InternalReverseNestedTests extends InternalSingleBucketAggregationT
protected Reader<InternalReverseNested> instanceReader() {
return InternalReverseNested::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedReverseNested.class;
}
}

View File

@ -21,6 +21,7 @@ package org.elasticsearch.search.aggregations.bucket.sampler;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import java.util.List;
@ -42,4 +43,9 @@ public class InternalSamplerTests extends InternalSingleBucketAggregationTestCas
protected Writeable.Reader<InternalSampler> instanceReader() {
return InternalSampler::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedSampler.class;
}
}

View File

@ -38,10 +38,24 @@ import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.children.ParsedChildren;
import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter;
import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.global.ParsedGlobal;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram;
import org.elasticsearch.search.aggregations.bucket.histogram.ParsedHistogram;
import org.elasticsearch.search.aggregations.bucket.missing.MissingAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.missing.ParsedMissing;
import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.nested.ParsedNested;
import org.elasticsearch.search.aggregations.bucket.nested.ParsedReverseNested;
import org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.sampler.InternalSampler;
import org.elasticsearch.search.aggregations.bucket.sampler.ParsedSampler;
import org.elasticsearch.search.aggregations.bucket.terms.DoubleTerms;
import org.elasticsearch.search.aggregations.bucket.terms.LongTerms;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedDoubleTerms;
@ -139,6 +153,13 @@ public abstract class InternalAggregationTestCase<T extends InternalAggregation>
namedXContents.put(StringTerms.NAME, (p, c) -> ParsedStringTerms.fromXContent(p, (String) c));
namedXContents.put(LongTerms.NAME, (p, c) -> ParsedLongTerms.fromXContent(p, (String) c));
namedXContents.put(DoubleTerms.NAME, (p, c) -> ParsedDoubleTerms.fromXContent(p, (String) c));
namedXContents.put(MissingAggregationBuilder.NAME, (p, c) -> ParsedMissing.fromXContent(p, (String) c));
namedXContents.put(NestedAggregationBuilder.NAME, (p, c) -> ParsedNested.fromXContent(p, (String) c));
namedXContents.put(ReverseNestedAggregationBuilder.NAME, (p, c) -> ParsedReverseNested.fromXContent(p, (String) c));
namedXContents.put(ChildrenAggregationBuilder.NAME, (p, c) -> ParsedChildren.fromXContent(p, (String) c));
namedXContents.put(GlobalAggregationBuilder.NAME, (p, c) -> ParsedGlobal.fromXContent(p, (String) c));
namedXContents.put(FilterAggregationBuilder.NAME, (p, c) -> ParsedFilter.fromXContent(p, (String) c));
namedXContents.put(InternalSampler.NAME, (p, c) -> ParsedSampler.fromXContent(p, (String) c));
return namedXContents.entrySet().stream()
.map(entry -> new NamedXContentRegistry.Entry(Aggregation.class, new ParseField(entry.getKey()), entry.getValue()))
@ -248,7 +269,7 @@ public abstract class InternalAggregationTestCase<T extends InternalAggregation>
}
//norelease TODO make abstract
protected void assertFromXContent(T aggregation, ParsedAggregation parsedAggregation) {
protected void assertFromXContent(T aggregation, ParsedAggregation parsedAggregation) throws IOException {
}
@SuppressWarnings("unchecked")