20
20
package org .elasticsearch .search .aggregations .metrics .geobounds ;
21
21
22
22
import org .apache .lucene .index .LeafReaderContext ;
23
+ import org .elasticsearch .common .ParseField ;
23
24
import org .elasticsearch .common .geo .GeoPoint ;
25
+ import org .elasticsearch .common .io .stream .StreamInput ;
26
+ import org .elasticsearch .common .io .stream .StreamOutput ;
24
27
import org .elasticsearch .common .lease .Releasables ;
25
28
import org .elasticsearch .common .util .BigArrays ;
26
29
import org .elasticsearch .common .util .DoubleArray ;
30
+ import org .elasticsearch .common .xcontent .XContentBuilder ;
27
31
import org .elasticsearch .index .fielddata .MultiGeoPointValues ;
28
32
import org .elasticsearch .search .aggregations .Aggregator ;
29
33
import org .elasticsearch .search .aggregations .InternalAggregation ;
32
36
import org .elasticsearch .search .aggregations .metrics .MetricsAggregator ;
33
37
import org .elasticsearch .search .aggregations .pipeline .PipelineAggregator ;
34
38
import org .elasticsearch .search .aggregations .support .AggregationContext ;
39
+ import org .elasticsearch .search .aggregations .support .ValueType ;
35
40
import org .elasticsearch .search .aggregations .support .ValuesSource ;
36
41
import org .elasticsearch .search .aggregations .support .ValuesSourceAggregatorFactory ;
37
- import org .elasticsearch .search .aggregations .support .ValuesSourceParser ;
42
+ import org .elasticsearch .search .aggregations .support .ValuesSourceType ;
38
43
39
44
import java .io .IOException ;
40
45
import java .util .List ;
41
46
import java .util .Map ;
47
+ import java .util .Objects ;
42
48
43
49
public final class GeoBoundsAggregator extends MetricsAggregator {
44
50
51
+ static final ParseField WRAP_LONGITUDE_FIELD = new ParseField ("wrap_longitude" );
52
+
45
53
private final ValuesSource .GeoPoint valuesSource ;
46
54
private final boolean wrapLongitude ;
47
55
DoubleArray tops ;
@@ -168,13 +176,26 @@ public void doClose() {
168
176
169
177
public static class Factory extends ValuesSourceAggregatorFactory <ValuesSource .GeoPoint > {
170
178
171
- private final boolean wrapLongitude ;
179
+ private boolean wrapLongitude = true ;
180
+
181
+ public Factory (String name ) {
182
+ super (name , InternalGeoBounds .TYPE , ValuesSourceType .GEOPOINT , ValueType .GEOPOINT );
183
+ }
172
184
173
- protected Factory (String name , ValuesSourceParser .Input <ValuesSource .GeoPoint > input , boolean wrapLongitude ) {
174
- super (name , InternalGeoBounds .TYPE , input );
185
+ /**
186
+ * Set whether to wrap longitudes. Defaults to true.
187
+ */
188
+ public void wrapLongitude (boolean wrapLongitude ) {
175
189
this .wrapLongitude = wrapLongitude ;
176
190
}
177
191
192
+ /**
193
+ * Get whether to wrap longitudes.
194
+ */
195
+ public boolean wrapLongitude () {
196
+ return wrapLongitude ;
197
+ }
198
+
178
199
@ Override
179
200
protected Aggregator createUnmapped (AggregationContext aggregationContext , Aggregator parent ,
180
201
List <PipelineAggregator > pipelineAggregators , Map <String , Object > metaData ) throws IOException {
@@ -188,5 +209,35 @@ protected Aggregator doCreateInternal(ValuesSource.GeoPoint valuesSource, Aggreg
188
209
return new GeoBoundsAggregator (name , aggregationContext , parent , valuesSource , wrapLongitude , pipelineAggregators , metaData );
189
210
}
190
211
212
+ @ Override
213
+ protected ValuesSourceAggregatorFactory <ValuesSource .GeoPoint > innerReadFrom (String name , ValuesSourceType valuesSourceType ,
214
+ ValueType targetValueType , StreamInput in ) throws IOException {
215
+ Factory factory = new Factory (name );
216
+ factory .wrapLongitude = in .readBoolean ();
217
+ return factory ;
218
+ }
219
+
220
+ @ Override
221
+ protected void innerWriteTo (StreamOutput out ) throws IOException {
222
+ out .writeBoolean (wrapLongitude );
223
+ }
224
+
225
+ @ Override
226
+ public XContentBuilder doXContentBody (XContentBuilder builder , Params params ) throws IOException {
227
+ builder .field (WRAP_LONGITUDE_FIELD .getPreferredName (), wrapLongitude );
228
+ return builder ;
229
+ }
230
+
231
+ @ Override
232
+ protected int innerHashCode () {
233
+ return Objects .hash (wrapLongitude );
234
+ }
235
+
236
+ @ Override
237
+ protected boolean innerEquals (Object obj ) {
238
+ Factory other = (Factory ) obj ;
239
+ return Objects .equals (wrapLongitude , other .wrapLongitude );
240
+ }
241
+
191
242
}
192
243
}
0 commit comments