Skip to content

Commit 39f2863

Browse files
author
Bapt Abl
committed
Upgrade plugin to 7.10
1 parent ea8e22e commit 39f2863

File tree

8 files changed

+269
-168
lines changed

8 files changed

+269
-168
lines changed

src/main/java/com/opendatasoft/elasticsearch/plugin/GeoPointClusteringAggregationPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public ArrayList<SearchPlugin.AggregationSpec> getAggregations() {
1818
GeoPointClusteringAggregationBuilder::new,
1919
GeoPointClusteringAggregationBuilder::parse)
2020
.addResultReader(InternalGeoPointClustering::new)
21+
.setAggregatorRegistrar(GeoPointClusteringAggregationBuilder::registerAggregators)
2122
);
2223

2324
return r;

src/main/java/com/opendatasoft/elasticsearch/search/aggregations/bucket/geopointclustering/GeoPointClustering.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import java.util.List;
66

77
/**
8-
* A {@code geopoint_clustering} aggregation.
9-
* precision.
8+
* A {@code geopoint_clustering} aggregation. Buckets key are centroids.
109
*/
1110
public interface GeoPointClustering extends MultiBucketsAggregation {
1211

src/main/java/com/opendatasoft/elasticsearch/search/aggregations/bucket/geopointclustering/GeoPointClusteringAggregationBuilder.java

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@
1212
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
1313
import org.elasticsearch.search.aggregations.AggregatorFactory;
1414
import org.elasticsearch.search.aggregations.bucket.BucketUtils;
15-
import org.elasticsearch.search.aggregations.bucket.MultiBucketAggregationBuilder;
1615
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
17-
import org.elasticsearch.search.aggregations.support.ValueType;
18-
import org.elasticsearch.search.aggregations.support.ValuesSource;
1916
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
2017
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
2118
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;
2321

2422
import java.io.IOException;
2523
import java.util.Map;
2624
import java.util.Objects;
2725

2826
public class GeoPointClusteringAggregationBuilder extends
29-
ValuesSourceAggregationBuilder<ValuesSource.GeoPoint, GeoPointClusteringAggregationBuilder>
30-
implements MultiBucketAggregationBuilder {
27+
ValuesSourceAggregationBuilder<GeoPointClusteringAggregationBuilder> {
3128
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+
3232
public static final int DEFAULT_ZOOM = 1;
33-
public static final int DEFAULT_RADIUS = 40;
3433
public static final int DEFAULT_EXTENT = 256;
3534
public static final int DEFAULT_MAX_NUM_CELLS = 10000;
35+
public static final int DEFAULT_RADIUS = 40;
3636
public static final double DEFAULT_RATIO = 0;
3737

3838
private static final ObjectParser<GeoPointClusteringAggregationBuilder, Void> PARSER;
3939
static {
4040
PARSER = new ObjectParser<>(GeoPointClusteringAggregationBuilder.NAME);
41-
ValuesSourceParserHelper.declareGeoFields(PARSER, false, false);
41+
ValuesSourceAggregationBuilder.declareFields(PARSER, false, false, false);
4242
PARSER.declareInt(GeoPointClusteringAggregationBuilder::size, GeoPointClusteringParams.FIELD_SIZE);
4343
PARSER.declareInt(GeoPointClusteringAggregationBuilder::shardSize, GeoPointClusteringParams.FIELD_SHARD_SIZE);
4444
PARSER.declareInt(GeoPointClusteringAggregationBuilder::zoom, GeoPointClusteringParams.FIELD_ZOOM);
@@ -60,7 +60,7 @@ public static GeoPointClusteringAggregationBuilder parse(String aggregationName,
6060
private double ratio = DEFAULT_RATIO;
6161

6262
public GeoPointClusteringAggregationBuilder(String name) {
63-
super(name, CoreValuesSourceType.GEOPOINT, ValueType.GEOPOINT);
63+
super(name);
6464
}
6565

6666
protected GeoPointClusteringAggregationBuilder(
@@ -83,7 +83,7 @@ protected AggregationBuilder shallowCopy(Builder factoriesBuilder, Map<String, O
8383
* Read from a stream.
8484
*/
8585
public GeoPointClusteringAggregationBuilder(StreamInput in) throws IOException {
86-
super(in, CoreValuesSourceType.GEOPOINT, ValueType.GEOPOINT);
86+
super(in);
8787
zoom = in.readInt();
8888
radius = in.readInt();
8989
extent = in.readInt();
@@ -92,6 +92,9 @@ public GeoPointClusteringAggregationBuilder(StreamInput in) throws IOException {
9292
shardSize = in.readVInt();
9393
}
9494

95+
/**
96+
* Write to stream.
97+
*/
9598
@Override
9699
protected void innerWriteTo(StreamOutput out) throws IOException {
97100
out.writeInt(zoom);
@@ -107,6 +110,16 @@ public GeoPointClusteringAggregationBuilder zoom(int zoom) {
107110
return this;
108111
}
109112

113+
@Override
114+
public BucketCardinality bucketCardinality() {
115+
return BucketCardinality.MANY;
116+
}
117+
118+
@Override
119+
protected ValuesSourceType defaultValueSourceType() {
120+
return CoreValuesSourceType.GEOPOINT;
121+
}
122+
110123
public int zoom() {
111124
return zoom;
112125
}
@@ -133,11 +146,6 @@ public GeoPointClusteringAggregationBuilder radius(int radius) {
133146
return this;
134147
}
135148

136-
public int radius() {
137-
return radius;
138-
}
139-
140-
141149
public GeoPointClusteringAggregationBuilder ratio(double ratio) {
142150
if (ratio > 2) {
143151
throw new IllegalArgumentException(
@@ -147,8 +155,9 @@ public GeoPointClusteringAggregationBuilder ratio(double ratio) {
147155
return this;
148156
}
149157

150-
public double ratio() {
151-
return ratio;
158+
@Override
159+
protected ValuesSourceRegistry.RegistryKey<?> getRegistryKey() {
160+
return REGISTRY_KEY;
152161
}
153162

154163
public GeoPointClusteringAggregationBuilder size(int size) {
@@ -173,15 +182,13 @@ public GeoPointClusteringAggregationBuilder shardSize(int shardSize) {
173182
return this;
174183
}
175184

176-
public int shardSize() {
177-
return shardSize;
178-
}
179-
180185
@Override
181-
protected ValuesSourceAggregatorFactory<ValuesSource.GeoPoint> innerBuild(
186+
protected ValuesSourceAggregatorFactory innerBuild(
182187
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 {
185192
int shardSize = this.shardSize;
186193

187194
int requiredSize = this.requiredSize;
@@ -218,7 +225,7 @@ protected ValuesSourceAggregatorFactory<ValuesSource.GeoPoint> innerBuild(
218225
int precision = GeoUtils.geoHashLevelsForPrecision(radius);
219226

220227
return new GeoPointClusteringAggregatorFactory(name, config, precision, radius, ratio, requiredSize, shardSize,
221-
context, parent, subFactoriesBuilder, metaData);
228+
context, parent, subFactoriesBuilder, metadata);
222229
}
223230

224231
@Override
@@ -267,4 +274,13 @@ public int hashCode() {
267274
public String getType() {
268275
return NAME;
269276
}
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+
270286
}

0 commit comments

Comments
 (0)