20
20
package org .elasticsearch .search .aggregations .bucket .missing ;
21
21
22
22
import org .elasticsearch .index .query .QueryShardContext ;
23
+ import org .elasticsearch .search .aggregations .AggregationExecutionException ;
23
24
import org .elasticsearch .search .aggregations .Aggregator ;
24
25
import org .elasticsearch .search .aggregations .AggregatorFactories ;
25
26
import org .elasticsearch .search .aggregations .AggregatorFactory ;
26
27
import org .elasticsearch .search .aggregations .pipeline .PipelineAggregator ;
28
+ import org .elasticsearch .search .aggregations .support .AggregatorSupplier ;
29
+ import org .elasticsearch .search .aggregations .support .CoreValuesSourceType ;
27
30
import org .elasticsearch .search .aggregations .support .ValuesSource ;
28
31
import org .elasticsearch .search .aggregations .support .ValuesSourceAggregatorFactory ;
29
32
import org .elasticsearch .search .aggregations .support .ValuesSourceConfig ;
33
+ import org .elasticsearch .search .aggregations .support .ValuesSourceRegistry ;
30
34
import org .elasticsearch .search .internal .SearchContext ;
31
35
32
36
import java .io .IOException ;
35
39
36
40
public class MissingAggregatorFactory extends ValuesSourceAggregatorFactory {
37
41
42
+ public static void registerAggregators (ValuesSourceRegistry valuesSourceRegistry ) {
43
+ valuesSourceRegistry .register (
44
+ MissingAggregationBuilder .NAME ,
45
+ List .of (
46
+ CoreValuesSourceType .NUMERIC ,
47
+ CoreValuesSourceType .BYTES ,
48
+ CoreValuesSourceType .GEOPOINT ,
49
+ CoreValuesSourceType .RANGE ,
50
+ CoreValuesSourceType .IP ,
51
+ CoreValuesSourceType .BOOLEAN ,
52
+ CoreValuesSourceType .DATE
53
+ ),
54
+ (MissingAggregatorSupplier ) MissingAggregator ::new
55
+ );
56
+ }
57
+
38
58
public MissingAggregatorFactory (String name , ValuesSourceConfig config , QueryShardContext queryShardContext ,
39
59
AggregatorFactory parent , AggregatorFactories .Builder subFactoriesBuilder ,
40
60
Map <String , Object > metaData ) throws IOException {
@@ -50,13 +70,22 @@ protected MissingAggregator createUnmapped(SearchContext searchContext,
50
70
}
51
71
52
72
@ Override
53
- protected MissingAggregator doCreateInternal (ValuesSource valuesSource ,
73
+ protected Aggregator doCreateInternal (ValuesSource valuesSource ,
54
74
SearchContext searchContext ,
55
75
Aggregator parent ,
56
76
boolean collectsFromSingleBucket ,
57
77
List <PipelineAggregator > pipelineAggregators ,
58
78
Map <String , Object > metaData ) throws IOException {
59
- return new MissingAggregator (name , factories , valuesSource , searchContext , parent , pipelineAggregators , metaData );
79
+
80
+ final AggregatorSupplier aggregatorSupplier = queryShardContext .getValuesSourceRegistry ()
81
+ .getAggregator (config .valueSourceType (), MissingAggregationBuilder .NAME );
82
+ if (aggregatorSupplier instanceof MissingAggregatorSupplier == false ) {
83
+ throw new AggregationExecutionException ("Registry miss-match - expected MissingAggregatorSupplier, found [" +
84
+ aggregatorSupplier .getClass ().toString () + "]" );
85
+ }
86
+
87
+ return ((MissingAggregatorSupplier ) aggregatorSupplier )
88
+ .build (name , factories , valuesSource , searchContext , parent , pipelineAggregators , metaData );
60
89
}
61
90
62
91
}
0 commit comments