Skip to content

Commit a90c1de

Browse files
not-napoleonpolyfractalcsouliostalevy
authored
Add ValuesSource Registry and associated logic (#54281)
* Remove ValuesSourceType argument to ValuesSourceAggregationBuilder (#48638) * ValuesSourceRegistry Prototype (#48758) * Remove generics from ValuesSource related classes (#49606) * fix percentile aggregation tests (#50712) * Basic thread safety for ValuesSourceRegistry (#50340) * Remove target value type from ValuesSourceAggregationBuilder (#49943) * Cleanup default values source type (#50992) * CoreValuesSourceType no longer implements Writable (#51276) * Remove genereics & hard coded ValuesSource references from Matrix Stats (#51131) * Put values source types on fields (#51503) * Remove VST Any (#51539) * Rewire terms agg to use new VS registry (#51182) Also adds some basic AggTestCases for untested code paths (and boilerplate for future tests once the IT are converted over) * Wire Cardinality aggregation to work with the ValuesSourceRegistry (#51337) * Wire Percentiles aggregator into new VS framework (#51639) This required a bit of a refactor to percentiles itself. Before, the Builder would switch on the chosen algo to generate an algo-specific factory. This doesn't work (or at least, would be difficult) in the new VS framework. This refactor consolidates both factories together and introduces a PercentilesConfig object to act as a standardized way to pass algo-specific parameters through the factory. This object is then used when deciding which kind of aggregator to create Note: CoreValuesSourceType.HISTOGRAM still lives in core, and will be moved in a subsequent PR. * Remove generics and target value type from MultiVSAB (#51647) * fix checkstyle after merge (#52008) * Plumb ValuesSourceRegistry through to QuerySearchContext (#51710) * Convert RareTerms to new VS registry (#52166) * Wire up Value Count (#52225) * Wire up Max & Min aggregations (#52219) * ValuesSource refactoring: Wire up Sum aggregation (#52571) * ValuesSource refactoring: Wire up SigTerms aggregation (#52590) * Soft immutability for VSConfig (#52729) * Unmute testSupportedFieldTypes, fix Percentiles/Ranks/Terms tests (#52734) Also fixes Percentiles which was incorrectly specified to only accept numeric, but in fact also accepts Boolean and Date (because those are numeric on master - thanks `testSupportedFieldTypes` for catching it!) * VS refactoring: Wire up stats aggregation (#52891) * ValuesSource refactoring: Wire up string_stats aggregation (#52875) * VS refactoring: Wire up median (MAD) aggregation (#52945) * fix valuesourcetype issue with constant_keyword field (#53041) this commit implements `getValuesSourceType` for the ConstantKeyword field type. master was merged into feature/extensible-values-source introducing a new field type that was not implementing `getValuesSourceType`. * ValuesSource refactoring: Wire up Avg aggregation (#52752) * Wire PercentileRanks aggregator into new VS framework (#51693) * Add a VSConfig resolver for aggregations not using the registry (#53038) * Vs refactor wire up ranges and date ranges (#52918) * Wire up geo_bounds aggregation to ValuesSourceRegistry (#53034) This commit updates the geo_bounds aggregation to depend on registering itself in the ValuesSourceRegistry relates #42949. * VS refactoring: convert Boxplot to new registry (#53132) * Wire-up geotile_grid and geohash_grid to ValuesSourceRegistry (#53037) This commit updates the geo*_grid aggregations to depend on registering itself in the ValuesSourceRegistry relates to the values-source refactoring meta issue #42949. * Wire-up geo_centroid agg to ValuesSourceRegistry (#53040) This commit updates the geo_centroid aggregation to depend on registering itself in the ValuesSourceRegistry. relates to the values-source refactoring meta issue #42949. * Fix type tests for Missing aggregation (#53501) * ValuesSource Refactor: move histo VSType into XPack module (#53298) - Introduces a new API (`getBareAggregatorRegistrar()`) which allows plugins to register aggregations against existing agg definitions defined in Core. - This moves the histogram VSType over to XPack where it belongs. `getHistogramValues()` still remains as a Core concept - Moves the histo-specific bits over to xpack (e.g. the actual aggregator logic). This requires extra boilerplate since we need to create a new "Analytics" Percentile/Rank aggregators to deal with the histo field. Doubly-so since percentiles/ranks are extra boiler-plate'y... should be much lighter for other aggs * Wire up DateHistogram to the ValuesSourceRegistry (#53484) * Vs refactor parser cleanup (#53198) Co-authored-by: Zachary Tong <[email protected]> Co-authored-by: Zachary Tong <[email protected]> Co-authored-by: Christos Soulios <[email protected]> Co-authored-by: Tal Levy <[email protected]>
1 parent 7bc130b commit a90c1de

File tree

248 files changed

+5491
-2352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+5491
-2352
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/analytics/StringStatsAggregationBuilder.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@
3030
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
3131
import org.elasticsearch.search.aggregations.AggregatorFactory;
3232
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
33-
import org.elasticsearch.search.aggregations.support.ValueType;
34-
import org.elasticsearch.search.aggregations.support.ValuesSource;
35-
import org.elasticsearch.search.aggregations.support.ValuesSource.Bytes;
3633
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
3734
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
3835
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
36+
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
3937
import org.elasticsearch.search.builder.SearchSourceBuilder;
4038

4139
import java.io.IOException;
@@ -52,14 +50,14 @@
5250
* {@linkplain AggregationBuilder#rewrite(QueryRewriteContext)}, or
5351
* {@linkplain AbstractAggregationBuilder#build(QueryShardContext, AggregatorFactory)}.
5452
*/
55-
public class StringStatsAggregationBuilder extends ValuesSourceAggregationBuilder<ValuesSource.Bytes, StringStatsAggregationBuilder> {
53+
public class StringStatsAggregationBuilder extends ValuesSourceAggregationBuilder<StringStatsAggregationBuilder> {
5654
public static final String NAME = "string_stats";
5755
private static final ParseField SHOW_DISTRIBUTION_FIELD = new ParseField("show_distribution");
5856

5957
private boolean showDistribution = false;
6058

6159
public StringStatsAggregationBuilder(String name) {
62-
super(name, CoreValuesSourceType.BYTES, ValueType.STRING);
60+
super(name);
6361
}
6462

6563
/**
@@ -71,6 +69,11 @@ public StringStatsAggregationBuilder showDistribution(boolean showDistribution)
7169
return this;
7270
}
7371

72+
@Override
73+
protected ValuesSourceType defaultValueSourceType() {
74+
return CoreValuesSourceType.BYTES;
75+
}
76+
7477
@Override
7578
public String getType() {
7679
return NAME;
@@ -87,7 +90,7 @@ protected void innerWriteTo(StreamOutput out) throws IOException {
8790
}
8891

8992
@Override
90-
protected ValuesSourceAggregatorFactory<Bytes> innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig<Bytes> config,
93+
protected ValuesSourceAggregatorFactory innerBuild(QueryShardContext queryShardContext, ValuesSourceConfig config,
9194
AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException {
9295
throw new UnsupportedOperationException();
9396
}

client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,8 @@ public static SearchSourceBuilder createTestSearchSourceBuilder() {
10771077
searchSourceBuilder.query(new TermQueryBuilder(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10)));
10781078
}
10791079
if (randomBoolean()) {
1080-
searchSourceBuilder.aggregation(new TermsAggregationBuilder(randomAlphaOfLengthBetween(3, 10), ValueType.STRING)
1080+
searchSourceBuilder.aggregation(new TermsAggregationBuilder(randomAlphaOfLengthBetween(3, 10))
1081+
.userValueTypeHint(ValueType.STRING)
10811082
.field(randomAlphaOfLengthBetween(3, 10)));
10821083
}
10831084
if (randomBoolean()) {

client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ public void testSearchMatchQuery() throws IOException {
257257
public void testSearchWithTermsAgg() throws IOException {
258258
SearchRequest searchRequest = new SearchRequest();
259259
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
260-
searchSourceBuilder.aggregation(new TermsAggregationBuilder("agg1", ValueType.STRING).field("type.keyword"));
260+
searchSourceBuilder.aggregation(new TermsAggregationBuilder("agg1").userValueTypeHint(ValueType.STRING)
261+
.field("type.keyword"));
261262
searchSourceBuilder.size(0);
262263
searchRequest.source(searchSourceBuilder);
263264
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
@@ -349,7 +350,7 @@ public void testSearchWithRangeAgg() throws IOException {
349350
public void testSearchWithTermsAndRangeAgg() throws IOException {
350351
SearchRequest searchRequest = new SearchRequest("index");
351352
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
352-
TermsAggregationBuilder agg = new TermsAggregationBuilder("agg1", ValueType.STRING).field("type.keyword");
353+
TermsAggregationBuilder agg = new TermsAggregationBuilder("agg1").userValueTypeHint(ValueType.STRING).field("type.keyword");
353354
agg.subAggregation(new RangeAggregationBuilder("subagg").field("num")
354355
.addRange("first", 0, 30).addRange("second", 31, 200));
355356
searchSourceBuilder.aggregation(agg);
@@ -403,7 +404,7 @@ public void testSearchWithTermsAndRangeAgg() throws IOException {
403404
public void testSearchWithTermsAndWeightedAvg() throws IOException {
404405
SearchRequest searchRequest = new SearchRequest("index");
405406
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
406-
TermsAggregationBuilder agg = new TermsAggregationBuilder("agg1", ValueType.STRING).field("type.keyword");
407+
TermsAggregationBuilder agg = new TermsAggregationBuilder("agg1").userValueTypeHint(ValueType.STRING).field("type.keyword");
407408
agg.subAggregation(new WeightedAvgAggregationBuilder("subagg")
408409
.value(new MultiValuesSourceFieldConfig.Builder().setFieldName("num").build())
409410
.weight(new MultiValuesSourceFieldConfig.Builder().setFieldName("num2").build())
@@ -529,10 +530,12 @@ public void testSearchWithParentJoin() throws IOException {
529530
client().performRequest(answerDoc2);
530531
client().performRequest(new Request(HttpPost.METHOD_NAME, "/_refresh"));
531532

532-
TermsAggregationBuilder leafTermAgg = new TermsAggregationBuilder("top-names", ValueType.STRING)
533+
TermsAggregationBuilder leafTermAgg = new TermsAggregationBuilder("top-names")
534+
.userValueTypeHint(ValueType.STRING)
533535
.field("owner.display_name.keyword").size(10);
534536
ChildrenAggregationBuilder childrenAgg = new ChildrenAggregationBuilder("to-answers", "answer").subAggregation(leafTermAgg);
535-
TermsAggregationBuilder termsAgg = new TermsAggregationBuilder("top-tags", ValueType.STRING).field("tags.keyword")
537+
TermsAggregationBuilder termsAgg = new TermsAggregationBuilder("top-tags").userValueTypeHint(ValueType.STRING)
538+
.field("tags.keyword")
536539
.size(10).subAggregation(childrenAgg);
537540
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
538541
searchSourceBuilder.size(0).aggregation(termsAgg);
@@ -744,15 +747,18 @@ public void testMultiSearch() throws Exception {
744747
public void testMultiSearch_withAgg() throws Exception {
745748
MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
746749
SearchRequest searchRequest1 = new SearchRequest("index1");
747-
searchRequest1.source().size(0).aggregation(new TermsAggregationBuilder("name", ValueType.STRING).field("field.keyword")
750+
searchRequest1.source().size(0).aggregation(new TermsAggregationBuilder("name").userValueTypeHint(ValueType.STRING)
751+
.field("field.keyword")
748752
.order(BucketOrder.key(true)));
749753
multiSearchRequest.add(searchRequest1);
750754
SearchRequest searchRequest2 = new SearchRequest("index2");
751-
searchRequest2.source().size(0).aggregation(new TermsAggregationBuilder("name", ValueType.STRING).field("field.keyword")
755+
searchRequest2.source().size(0).aggregation(new TermsAggregationBuilder("name").userValueTypeHint(ValueType.STRING)
756+
.field("field.keyword")
752757
.order(BucketOrder.key(true)));
753758
multiSearchRequest.add(searchRequest2);
754759
SearchRequest searchRequest3 = new SearchRequest("index3");
755-
searchRequest3.source().size(0).aggregation(new TermsAggregationBuilder("name", ValueType.STRING).field("field.keyword")
760+
searchRequest3.source().size(0).aggregation(new TermsAggregationBuilder("name").userValueTypeHint(ValueType.STRING)
761+
.field("field.keyword")
756762
.order(BucketOrder.key(true)));
757763
multiSearchRequest.add(searchRequest3);
758764

modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/MatrixStatsAggregationBuilder.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,19 @@
2828
import org.elasticsearch.search.aggregations.AggregatorFactories;
2929
import org.elasticsearch.search.aggregations.AggregatorFactory;
3030
import org.elasticsearch.search.aggregations.support.ArrayValuesSourceAggregationBuilder;
31-
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
32-
import org.elasticsearch.search.aggregations.support.ValueType;
33-
import org.elasticsearch.search.aggregations.support.ValuesSource;
34-
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
3531
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
3632

3733
import java.io.IOException;
3834
import java.util.Map;
3935

4036
public class MatrixStatsAggregationBuilder
41-
extends ArrayValuesSourceAggregationBuilder.LeafOnly<ValuesSource.Numeric, MatrixStatsAggregationBuilder> {
37+
extends ArrayValuesSourceAggregationBuilder.LeafOnly<MatrixStatsAggregationBuilder> {
4238
public static final String NAME = "matrix_stats";
4339

4440
private MultiValueMode multiValueMode = MultiValueMode.AVG;
4541

4642
public MatrixStatsAggregationBuilder(String name) {
47-
super(name, CoreValuesSourceType.NUMERIC, ValueType.NUMERIC);
43+
super(name);
4844
}
4945

5046
protected MatrixStatsAggregationBuilder(MatrixStatsAggregationBuilder clone,
@@ -62,7 +58,7 @@ protected AggregationBuilder shallowCopy(AggregatorFactories.Builder factoriesBu
6258
* Read from a stream.
6359
*/
6460
public MatrixStatsAggregationBuilder(StreamInput in) throws IOException {
65-
super(in, CoreValuesSourceType.NUMERIC, ValueType.NUMERIC);
61+
super(in);
6662
}
6763

6864
@Override
@@ -81,7 +77,7 @@ public MultiValueMode multiValueMode() {
8177

8278
@Override
8379
protected MatrixStatsAggregatorFactory innerBuild(QueryShardContext queryShardContext,
84-
Map<String, ValuesSourceConfig<Numeric>> configs,
80+
Map<String, ValuesSourceConfig> configs,
8581
AggregatorFactory parent,
8682
AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
8783
return new MatrixStatsAggregatorFactory(name, configs, multiValueMode, queryShardContext, parent, subFactoriesBuilder, metaData);

modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/MatrixStatsAggregatorFactory.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.elasticsearch.index.query.QueryShardContext;
2222
import org.elasticsearch.search.MultiValueMode;
23+
import org.elasticsearch.search.aggregations.AggregationExecutionException;
2324
import org.elasticsearch.search.aggregations.Aggregator;
2425
import org.elasticsearch.search.aggregations.AggregatorFactories;
2526
import org.elasticsearch.search.aggregations.AggregatorFactory;
@@ -30,15 +31,16 @@
3031
import org.elasticsearch.search.internal.SearchContext;
3132

3233
import java.io.IOException;
34+
import java.util.HashMap;
3335
import java.util.List;
3436
import java.util.Map;
3537

36-
final class MatrixStatsAggregatorFactory extends ArrayValuesSourceAggregatorFactory<ValuesSource.Numeric> {
38+
final class MatrixStatsAggregatorFactory extends ArrayValuesSourceAggregatorFactory {
3739

3840
private final MultiValueMode multiValueMode;
3941

4042
MatrixStatsAggregatorFactory(String name,
41-
Map<String, ValuesSourceConfig<ValuesSource.Numeric>> configs,
43+
Map<String, ValuesSourceConfig> configs,
4244
MultiValueMode multiValueMode,
4345
QueryShardContext queryShardContext,
4446
AggregatorFactory parent,
@@ -58,12 +60,21 @@ protected Aggregator createUnmapped(SearchContext searchContext,
5860
}
5961

6062
@Override
61-
protected Aggregator doCreateInternal(Map<String, ValuesSource.Numeric> valuesSources,
63+
protected Aggregator doCreateInternal(Map<String, ValuesSource> valuesSources,
6264
SearchContext searchContext,
6365
Aggregator parent,
6466
boolean collectsFromSingleBucket,
6567
List<PipelineAggregator> pipelineAggregators,
6668
Map<String, Object> metaData) throws IOException {
67-
return new MatrixStatsAggregator(name, valuesSources, searchContext, parent, multiValueMode, pipelineAggregators, metaData);
69+
Map<String, ValuesSource.Numeric> typedValuesSources = new HashMap<>(valuesSources.size());
70+
for (Map.Entry<String, ValuesSource> entry : valuesSources.entrySet()) {
71+
if (entry.getValue() instanceof ValuesSource.Numeric == false) {
72+
throw new AggregationExecutionException("ValuesSource type " + entry.getValue().toString() +
73+
"is not supported for aggregation " + this.name());
74+
}
75+
// TODO: There must be a better option than this.
76+
typedValuesSources.put(entry.getKey(), (ValuesSource.Numeric) entry.getValue());
77+
}
78+
return new MatrixStatsAggregator(name, typedValuesSources, searchContext, parent, multiValueMode, pipelineAggregators, metaData);
6879
}
6980
}

0 commit comments

Comments
 (0)