|
9 | 9 |
|
10 | 10 | import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
11 | 11 | import org.elasticsearch.common.io.stream.Writeable.Reader;
|
| 12 | +import org.elasticsearch.search.aggregations.AggregationInitializationException; |
12 | 13 | import org.elasticsearch.search.aggregations.AggregatorFactories;
|
13 | 14 | import org.elasticsearch.search.aggregations.BaseAggregationBuilder;
|
14 | 15 | import org.elasticsearch.search.aggregations.support.MultiValuesSourceFieldConfig;
|
@@ -101,6 +102,26 @@ public void testClientBuilder() throws IOException {
|
101 | 102 | }).test();
|
102 | 103 | }
|
103 | 104 |
|
| 105 | + public void testValidation() { |
| 106 | + AggregationInitializationException e = expectThrows(AggregationInitializationException.class, () -> { |
| 107 | + List<SortBuilder<?>> sortBuilders = singletonList( |
| 108 | + new FieldSortBuilder(randomAlphaOfLength(5)).order(randomFrom(SortOrder.values())) |
| 109 | + ); |
| 110 | + List<MultiValuesSourceFieldConfig> metricFields = InternalTopMetricsTests.randomMetricNames(between(1, 5)) |
| 111 | + .stream() |
| 112 | + .map(name -> { |
| 113 | + MultiValuesSourceFieldConfig.Builder metricField = new MultiValuesSourceFieldConfig.Builder(); |
| 114 | + metricField.setFieldName(randomAlphaOfLength(5)).setMissing(1.0); |
| 115 | + return metricField.build(); |
| 116 | + }) |
| 117 | + .collect(toList()); |
| 118 | + new TopMetricsAggregationBuilder("tm", sortBuilders, between(1, 100), metricFields).subAggregations( |
| 119 | + AggregatorFactories.builder() |
| 120 | + ); |
| 121 | + }); |
| 122 | + assertEquals("Aggregator [tm] of type [top_metrics] cannot accept sub-aggregations", e.getMessage()); |
| 123 | + } |
| 124 | + |
104 | 125 | private void toXContentThroughClientBuilder(TopMetricsAggregationBuilder serverBuilder, XContentBuilder builder) throws IOException {
|
105 | 126 | builder.startObject();
|
106 | 127 | createClientBuilder(serverBuilder).toXContent(builder, ToXContent.EMPTY_PARAMS);
|
|
0 commit comments