12
12
import org .elasticsearch .search .aggregations .AggregatorFactories .Builder ;
13
13
import org .elasticsearch .search .aggregations .AggregatorFactory ;
14
14
import org .elasticsearch .search .aggregations .bucket .BucketUtils ;
15
- import org .elasticsearch .search .aggregations .bucket .MultiBucketAggregationBuilder ;
16
15
import org .elasticsearch .search .aggregations .support .CoreValuesSourceType ;
17
- import org .elasticsearch .search .aggregations .support .ValueType ;
18
- import org .elasticsearch .search .aggregations .support .ValuesSource ;
19
16
import org .elasticsearch .search .aggregations .support .ValuesSourceAggregationBuilder ;
20
17
import org .elasticsearch .search .aggregations .support .ValuesSourceAggregatorFactory ;
21
18
import org .elasticsearch .search .aggregations .support .ValuesSourceConfig ;
22
- import org .elasticsearch .search .aggregations .support .ValuesSourceParserHelper ;
19
+ import org .elasticsearch .search .aggregations .support .ValuesSourceRegistry ;
20
+ import org .elasticsearch .search .aggregations .support .ValuesSourceType ;
23
21
24
22
import java .io .IOException ;
25
23
import java .util .Map ;
26
24
import java .util .Objects ;
27
25
28
26
public class GeoPointClusteringAggregationBuilder extends
29
- ValuesSourceAggregationBuilder <ValuesSource .GeoPoint , GeoPointClusteringAggregationBuilder >
30
- implements MultiBucketAggregationBuilder {
27
+ ValuesSourceAggregationBuilder <GeoPointClusteringAggregationBuilder > {
31
28
public static final String NAME = "geo_point_clustering" ;
29
+ public static final ValuesSourceRegistry .RegistryKey <GeoPointClusteringAggregatorSupplier > REGISTRY_KEY =
30
+ new ValuesSourceRegistry .RegistryKey <>(NAME , GeoPointClusteringAggregatorSupplier .class );
31
+
32
32
public static final int DEFAULT_ZOOM = 1 ;
33
- public static final int DEFAULT_RADIUS = 40 ;
34
33
public static final int DEFAULT_EXTENT = 256 ;
35
34
public static final int DEFAULT_MAX_NUM_CELLS = 10000 ;
35
+ public static final int DEFAULT_RADIUS = 40 ;
36
36
public static final double DEFAULT_RATIO = 0 ;
37
37
38
38
private static final ObjectParser <GeoPointClusteringAggregationBuilder , Void > PARSER ;
39
39
static {
40
40
PARSER = new ObjectParser <>(GeoPointClusteringAggregationBuilder .NAME );
41
- ValuesSourceParserHelper . declareGeoFields (PARSER , false , false );
41
+ ValuesSourceAggregationBuilder . declareFields (PARSER , false , false , false );
42
42
PARSER .declareInt (GeoPointClusteringAggregationBuilder ::size , GeoPointClusteringParams .FIELD_SIZE );
43
43
PARSER .declareInt (GeoPointClusteringAggregationBuilder ::shardSize , GeoPointClusteringParams .FIELD_SHARD_SIZE );
44
44
PARSER .declareInt (GeoPointClusteringAggregationBuilder ::zoom , GeoPointClusteringParams .FIELD_ZOOM );
@@ -60,7 +60,7 @@ public static GeoPointClusteringAggregationBuilder parse(String aggregationName,
60
60
private double ratio = DEFAULT_RATIO ;
61
61
62
62
public GeoPointClusteringAggregationBuilder (String name ) {
63
- super (name , CoreValuesSourceType . GEOPOINT , ValueType . GEOPOINT );
63
+ super (name );
64
64
}
65
65
66
66
protected GeoPointClusteringAggregationBuilder (
@@ -83,7 +83,7 @@ protected AggregationBuilder shallowCopy(Builder factoriesBuilder, Map<String, O
83
83
* Read from a stream.
84
84
*/
85
85
public GeoPointClusteringAggregationBuilder (StreamInput in ) throws IOException {
86
- super (in , CoreValuesSourceType . GEOPOINT , ValueType . GEOPOINT );
86
+ super (in );
87
87
zoom = in .readInt ();
88
88
radius = in .readInt ();
89
89
extent = in .readInt ();
@@ -92,6 +92,9 @@ public GeoPointClusteringAggregationBuilder(StreamInput in) throws IOException {
92
92
shardSize = in .readVInt ();
93
93
}
94
94
95
+ /**
96
+ * Write to stream.
97
+ */
95
98
@ Override
96
99
protected void innerWriteTo (StreamOutput out ) throws IOException {
97
100
out .writeInt (zoom );
@@ -107,6 +110,16 @@ public GeoPointClusteringAggregationBuilder zoom(int zoom) {
107
110
return this ;
108
111
}
109
112
113
+ @ Override
114
+ public BucketCardinality bucketCardinality () {
115
+ return BucketCardinality .MANY ;
116
+ }
117
+
118
+ @ Override
119
+ protected ValuesSourceType defaultValueSourceType () {
120
+ return CoreValuesSourceType .GEOPOINT ;
121
+ }
122
+
110
123
public int zoom () {
111
124
return zoom ;
112
125
}
@@ -133,11 +146,6 @@ public GeoPointClusteringAggregationBuilder radius(int radius) {
133
146
return this ;
134
147
}
135
148
136
- public int radius () {
137
- return radius ;
138
- }
139
-
140
-
141
149
public GeoPointClusteringAggregationBuilder ratio (double ratio ) {
142
150
if (ratio > 2 ) {
143
151
throw new IllegalArgumentException (
@@ -147,8 +155,9 @@ public GeoPointClusteringAggregationBuilder ratio(double ratio) {
147
155
return this ;
148
156
}
149
157
150
- public double ratio () {
151
- return ratio ;
158
+ @ Override
159
+ protected ValuesSourceRegistry .RegistryKey <?> getRegistryKey () {
160
+ return REGISTRY_KEY ;
152
161
}
153
162
154
163
public GeoPointClusteringAggregationBuilder size (int size ) {
@@ -173,15 +182,13 @@ public GeoPointClusteringAggregationBuilder shardSize(int shardSize) {
173
182
return this ;
174
183
}
175
184
176
- public int shardSize () {
177
- return shardSize ;
178
- }
179
-
180
185
@ Override
181
- protected ValuesSourceAggregatorFactory < ValuesSource . GeoPoint > innerBuild (
186
+ protected ValuesSourceAggregatorFactory innerBuild (
182
187
QueryShardContext context ,
183
- ValuesSourceConfig <ValuesSource .GeoPoint > config , AggregatorFactory parent , Builder subFactoriesBuilder )
184
- throws IOException {
188
+ ValuesSourceConfig config ,
189
+ AggregatorFactory parent ,
190
+ Builder subFactoriesBuilder
191
+ ) throws IOException {
185
192
int shardSize = this .shardSize ;
186
193
187
194
int requiredSize = this .requiredSize ;
@@ -218,7 +225,7 @@ protected ValuesSourceAggregatorFactory<ValuesSource.GeoPoint> innerBuild(
218
225
int precision = GeoUtils .geoHashLevelsForPrecision (radius );
219
226
220
227
return new GeoPointClusteringAggregatorFactory (name , config , precision , radius , ratio , requiredSize , shardSize ,
221
- context , parent , subFactoriesBuilder , metaData );
228
+ context , parent , subFactoriesBuilder , metadata );
222
229
}
223
230
224
231
@ Override
@@ -267,4 +274,13 @@ public int hashCode() {
267
274
public String getType () {
268
275
return NAME ;
269
276
}
277
+
278
+ public static void registerAggregators (ValuesSourceRegistry .Builder builder ) {
279
+ builder .register (
280
+ GeoPointClusteringAggregationBuilder .REGISTRY_KEY ,
281
+ CoreValuesSourceType .GEOPOINT ,
282
+ GeoPointClusteringAggregator ::new ,
283
+ true );
284
+ }
285
+
270
286
}
0 commit comments