19
19
20
20
package org .elasticsearch .search .aggregations .bucket .composite ;
21
21
22
+ import org .elasticsearch .Version ;
22
23
import org .elasticsearch .common .ParseField ;
24
+ import org .elasticsearch .common .geo .GeoBoundingBox ;
25
+ import org .elasticsearch .common .geo .GeoPoint ;
23
26
import org .elasticsearch .common .io .stream .StreamInput ;
24
27
import org .elasticsearch .common .io .stream .StreamOutput ;
25
28
import org .elasticsearch .common .xcontent .ObjectParser ;
@@ -45,6 +48,8 @@ public class GeoTileGridValuesSourceBuilder extends CompositeValuesSourceBuilder
45
48
static {
46
49
PARSER = new ObjectParser <>(GeoTileGridValuesSourceBuilder .TYPE );
47
50
PARSER .declareInt (GeoTileGridValuesSourceBuilder ::precision , new ParseField ("precision" ));
51
+ PARSER .declareField (((p , builder , context ) -> builder .geoBoundingBox (GeoBoundingBox .parseBoundingBox (p ))),
52
+ GeoBoundingBox .BOUNDS_FIELD , ObjectParser .ValueType .OBJECT );
48
53
CompositeValuesSourceParserHelper .declareValuesSourceFields (PARSER , ValueType .NUMERIC );
49
54
}
50
55
@@ -53,6 +58,7 @@ static GeoTileGridValuesSourceBuilder parse(String name, XContentParser parser)
53
58
}
54
59
55
60
private int precision = GeoTileGridAggregationBuilder .DEFAULT_PRECISION ;
61
+ private GeoBoundingBox geoBoundingBox = new GeoBoundingBox (new GeoPoint (Double .NaN , Double .NaN ), new GeoPoint (Double .NaN , Double .NaN ));
56
62
57
63
GeoTileGridValuesSourceBuilder (String name ) {
58
64
super (name );
@@ -61,13 +67,21 @@ static GeoTileGridValuesSourceBuilder parse(String name, XContentParser parser)
61
67
GeoTileGridValuesSourceBuilder (StreamInput in ) throws IOException {
62
68
super (in );
63
69
this .precision = in .readInt ();
70
+ if (in .getVersion ().onOrAfter (Version .V_8_0_0 )) {
71
+ this .geoBoundingBox = new GeoBoundingBox (in );
72
+ }
64
73
}
65
74
66
75
public GeoTileGridValuesSourceBuilder precision (int precision ) {
67
76
this .precision = GeoTileUtils .checkPrecisionRange (precision );
68
77
return this ;
69
78
}
70
79
80
+ public GeoTileGridValuesSourceBuilder geoBoundingBox (GeoBoundingBox geoBoundingBox ) {
81
+ this .geoBoundingBox = geoBoundingBox ;
82
+ return this ;
83
+ }
84
+
71
85
@ Override
72
86
public GeoTileGridValuesSourceBuilder format (String format ) {
73
87
throw new IllegalArgumentException ("[format] is not supported for [" + TYPE + "]" );
@@ -76,11 +90,17 @@ public GeoTileGridValuesSourceBuilder format(String format) {
76
90
@ Override
77
91
protected void innerWriteTo (StreamOutput out ) throws IOException {
78
92
out .writeInt (precision );
93
+ if (out .getVersion ().onOrAfter (Version .V_8_0_0 )) {
94
+ geoBoundingBox .writeTo (out );
95
+ }
79
96
}
80
97
81
98
@ Override
82
99
protected void doXContentBody (XContentBuilder builder , Params params ) throws IOException {
83
100
builder .field ("precision" , precision );
101
+ if (geoBoundingBox .isUnbounded () == false ) {
102
+ geoBoundingBox .toXContent (builder , params );
103
+ }
84
104
}
85
105
86
106
@ Override
@@ -90,7 +110,7 @@ String type() {
90
110
91
111
@ Override
92
112
public int hashCode () {
93
- return Objects .hash (super .hashCode (), precision );
113
+ return Objects .hash (super .hashCode (), precision , geoBoundingBox );
94
114
}
95
115
96
116
@ Override
@@ -99,7 +119,8 @@ public boolean equals(Object obj) {
99
119
if (obj == null || getClass () != obj .getClass ()) return false ;
100
120
if (super .equals (obj ) == false ) return false ;
101
121
GeoTileGridValuesSourceBuilder other = (GeoTileGridValuesSourceBuilder ) obj ;
102
- return precision == other .precision ;
122
+ return Objects .equals (precision ,other .precision )
123
+ && Objects .equals (geoBoundingBox , other .geoBoundingBox );
103
124
}
104
125
105
126
@ Override
@@ -112,7 +133,7 @@ protected CompositeValuesSourceConfig innerBuild(QueryShardContext queryShardCon
112
133
ValuesSource .GeoPoint geoPoint = (ValuesSource .GeoPoint ) orig ;
113
134
// is specified in the builder.
114
135
final MappedFieldType fieldType = config .fieldContext () != null ? config .fieldContext ().fieldType () : null ;
115
- CellIdSource cellIdSource = new CellIdSource (geoPoint , precision , GeoTileUtils ::longEncode );
136
+ CellIdSource cellIdSource = new CellIdSource (geoPoint , precision , geoBoundingBox , GeoTileUtils ::longEncode );
116
137
return new CompositeValuesSourceConfig (name , fieldType , cellIdSource , DocValueFormat .GEOTILE , order (),
117
138
missingBucket (), script () != null );
118
139
} else {
0 commit comments