22
22
import org .apache .lucene .search .MatchNoDocsQuery ;
23
23
import org .apache .lucene .search .Query ;
24
24
import org .apache .lucene .util .SetOnce ;
25
+ import org .elasticsearch .Version ;
25
26
import org .elasticsearch .action .ActionListener ;
26
27
import org .elasticsearch .action .get .GetRequest ;
27
28
import org .elasticsearch .action .get .GetResponse ;
28
29
import org .elasticsearch .client .Client ;
29
- import org .elasticsearch .common .Nullable ;
30
30
import org .elasticsearch .common .ParseField ;
31
31
import org .elasticsearch .common .ParsingException ;
32
32
import org .elasticsearch .common .geo .GeoJson ;
43
43
import org .elasticsearch .common .xcontent .XContentParser ;
44
44
import org .elasticsearch .geometry .Geometry ;
45
45
import org .elasticsearch .index .mapper .MappedFieldType ;
46
+ import org .elasticsearch .index .mapper .MapperService ;
46
47
47
48
import java .io .IOException ;
48
49
import java .util .ArrayList ;
55
56
*/
56
57
public abstract class AbstractGeometryQueryBuilder <QB extends AbstractGeometryQueryBuilder <QB >> extends AbstractQueryBuilder <QB > {
57
58
58
- static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Types are deprecated in [geo_shape] queries. " +
59
- "The type should no longer be specified in the [indexed_shape] section." ;
60
-
61
59
public static final String DEFAULT_SHAPE_INDEX_NAME = "shapes" ;
62
60
public static final String DEFAULT_SHAPE_FIELD_NAME = "shape" ;
63
61
public static final ShapeRelation DEFAULT_SHAPE_RELATION = ShapeRelation .INTERSECTS ;
@@ -72,7 +70,6 @@ public abstract class AbstractGeometryQueryBuilder<QB extends AbstractGeometryQu
72
70
protected static final ParseField RELATION_FIELD = new ParseField ("relation" );
73
71
protected static final ParseField INDEXED_SHAPE_FIELD = new ParseField ("indexed_shape" );
74
72
protected static final ParseField SHAPE_ID_FIELD = new ParseField ("id" );
75
- protected static final ParseField SHAPE_TYPE_FIELD = new ParseField ("type" );
76
73
protected static final ParseField SHAPE_INDEX_FIELD = new ParseField ("index" );
77
74
protected static final ParseField SHAPE_PATH_FIELD = new ParseField ("path" );
78
75
protected static final ParseField SHAPE_ROUTING_FIELD = new ParseField ("routing" );
@@ -82,7 +79,6 @@ public abstract class AbstractGeometryQueryBuilder<QB extends AbstractGeometryQu
82
79
protected final Supplier <Geometry > supplier ;
83
80
84
81
protected final String indexedShapeId ;
85
- protected final String indexedShapeType ;
86
82
87
83
protected Geometry shape ;
88
84
protected String indexedShapeIndex = DEFAULT_SHAPE_INDEX_NAME ;
@@ -105,7 +101,7 @@ public abstract class AbstractGeometryQueryBuilder<QB extends AbstractGeometryQu
105
101
*/
106
102
@ Deprecated
107
103
protected AbstractGeometryQueryBuilder (String fieldName , ShapeBuilder shape ) {
108
- this (fieldName , shape == null ? null : shape .buildGeometry (), null , null );
104
+ this (fieldName , shape == null ? null : shape .buildGeometry (), null );
109
105
}
110
106
111
107
/**
@@ -118,7 +114,7 @@ protected AbstractGeometryQueryBuilder(String fieldName, ShapeBuilder shape) {
118
114
* Shape used in the Query
119
115
*/
120
116
public AbstractGeometryQueryBuilder (String fieldName , Geometry shape ) {
121
- this (fieldName , shape , null , null );
117
+ this (fieldName , shape , null );
122
118
}
123
119
124
120
/**
@@ -131,28 +127,10 @@ public AbstractGeometryQueryBuilder(String fieldName, Geometry shape) {
131
127
* ID of the indexed Shape that will be used in the Query
132
128
*/
133
129
protected AbstractGeometryQueryBuilder (String fieldName , String indexedShapeId ) {
134
- this (fieldName , (Geometry ) null , indexedShapeId , null );
130
+ this (fieldName , (Geometry ) null , indexedShapeId );
135
131
}
136
132
137
- /**
138
- * Creates a new AbstractGeometryQueryBuilder whose Query will be against the given
139
- * field name and will use the Shape found with the given ID in the given
140
- * type
141
- *
142
- * @param fieldName
143
- * Name of the field that will be filtered
144
- * @param indexedShapeId
145
- * ID of the indexed Shape that will be used in the Query
146
- * @param indexedShapeType
147
- * Index type of the indexed Shapes
148
- * @deprecated use {@link #AbstractGeometryQueryBuilder(String, String)} instead
149
- */
150
- @ Deprecated
151
- protected AbstractGeometryQueryBuilder (String fieldName , String indexedShapeId , String indexedShapeType ) {
152
- this (fieldName , (Geometry ) null , indexedShapeId , indexedShapeType );
153
- }
154
-
155
- protected AbstractGeometryQueryBuilder (String fieldName , Geometry shape , String indexedShapeId , @ Nullable String indexedShapeType ) {
133
+ protected AbstractGeometryQueryBuilder (String fieldName , Geometry shape , String indexedShapeId ) {
156
134
if (fieldName == null ) {
157
135
throw new IllegalArgumentException ("fieldName is required" );
158
136
}
@@ -162,17 +140,20 @@ protected AbstractGeometryQueryBuilder(String fieldName, Geometry shape, String
162
140
this .fieldName = fieldName ;
163
141
this .shape = shape ;
164
142
this .indexedShapeId = indexedShapeId ;
165
- this .indexedShapeType = indexedShapeType ;
166
143
this .supplier = null ;
167
144
}
168
145
169
- protected AbstractGeometryQueryBuilder (String fieldName , Supplier <Geometry > supplier , String indexedShapeId ,
170
- @ Nullable String indexedShapeType ) {
146
+ protected AbstractGeometryQueryBuilder (String fieldName , Supplier <Geometry > supplier , String indexedShapeId ) {
147
+ if (fieldName == null ) {
148
+ throw new IllegalArgumentException ("fieldName is required" );
149
+ }
150
+ if (supplier == null && indexedShapeId == null ) {
151
+ throw new IllegalArgumentException ("either shape or indexedShapeId is required" );
152
+ }
171
153
this .fieldName = fieldName ;
172
154
this .shape = null ;
173
155
this .supplier = supplier ;
174
- this .indexedShapeId = indexedShapeId ;
175
- this .indexedShapeType = indexedShapeType ;
156
+ this .indexedShapeId = indexedShapeId ;;
176
157
}
177
158
178
159
/**
@@ -184,11 +165,13 @@ protected AbstractGeometryQueryBuilder(StreamInput in) throws IOException {
184
165
if (in .readBoolean ()) {
185
166
shape = GeometryIO .readGeometry (in );
186
167
indexedShapeId = null ;
187
- indexedShapeType = null ;
188
168
} else {
189
169
shape = null ;
190
170
indexedShapeId = in .readOptionalString ();
191
- indexedShapeType = in .readOptionalString ();
171
+ if (in .getVersion ().before (Version .V_8_0_0 )) {
172
+ String type = in .readOptionalString ();
173
+ assert MapperService .SINGLE_MAPPING_NAME .equals (type ) : "Expected type [_doc], got [" + type + "]" ;
174
+ }
192
175
indexedShapeIndex = in .readOptionalString ();
193
176
indexedShapePath = in .readOptionalString ();
194
177
indexedShapeRouting = in .readOptionalString ();
@@ -210,7 +193,9 @@ protected void doWriteTo(StreamOutput out) throws IOException {
210
193
GeometryIO .writeGeometry (out , shape );
211
194
} else {
212
195
out .writeOptionalString (indexedShapeId );
213
- out .writeOptionalString (indexedShapeType );
196
+ if (out .getVersion ().before (Version .V_8_0_0 )) {
197
+ out .writeOptionalString (MapperService .SINGLE_MAPPING_NAME );
198
+ }
214
199
out .writeOptionalString (indexedShapeIndex );
215
200
out .writeOptionalString (indexedShapePath );
216
201
out .writeOptionalString (indexedShapeRouting );
@@ -254,17 +239,6 @@ public String indexedShapeId() {
254
239
return indexedShapeId ;
255
240
}
256
241
257
- /**
258
- * @return the document type of the indexed Shape that will be used in the
259
- * Query
260
- *
261
- * @deprecated Types are in the process of being removed.
262
- */
263
- @ Deprecated
264
- public String indexedShapeType () {
265
- return indexedShapeType ;
266
- }
267
-
268
242
/**
269
243
* Sets the name of the index where the indexed Shape can be found
270
244
*
@@ -372,9 +346,9 @@ public boolean ignoreUnmapped() {
372
346
protected abstract void doShapeQueryXContent (XContentBuilder builder , Params params ) throws IOException ;
373
347
/** creates a new ShapeQueryBuilder from the provided field name and shape builder */
374
348
protected abstract AbstractGeometryQueryBuilder <QB > newShapeQueryBuilder (String fieldName , Geometry shape );
375
- /** creates a new ShapeQueryBuilder from the provided field name, supplier, indexed shape id, and indexed shape type */
349
+ /** creates a new ShapeQueryBuilder from the provided field name, supplier and indexed shape id */
376
350
protected abstract AbstractGeometryQueryBuilder <QB > newShapeQueryBuilder (String fieldName , Supplier <Geometry > shapeSupplier ,
377
- String indexedShapeId , String indexedShapeType );
351
+ String indexedShapeId );
378
352
379
353
/** returns true if the provided field type is valid for this query */
380
354
protected boolean isValidContentType (String typeName ) {
@@ -469,9 +443,6 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
469
443
} else {
470
444
builder .startObject (INDEXED_SHAPE_FIELD .getPreferredName ())
471
445
.field (SHAPE_ID_FIELD .getPreferredName (), indexedShapeId );
472
- if (indexedShapeType != null ) {
473
- builder .field (SHAPE_TYPE_FIELD .getPreferredName (), indexedShapeType );
474
- }
475
446
if (indexedShapeIndex != null ) {
476
447
builder .field (SHAPE_INDEX_FIELD .getPreferredName (), indexedShapeIndex );
477
448
}
@@ -503,7 +474,6 @@ protected boolean doEquals(AbstractGeometryQueryBuilder other) {
503
474
&& Objects .equals (indexedShapeId , other .indexedShapeId )
504
475
&& Objects .equals (indexedShapeIndex , other .indexedShapeIndex )
505
476
&& Objects .equals (indexedShapePath , other .indexedShapePath )
506
- && Objects .equals (indexedShapeType , other .indexedShapeType )
507
477
&& Objects .equals (indexedShapeRouting , other .indexedShapeRouting )
508
478
&& Objects .equals (relation , other .relation )
509
479
&& Objects .equals (shape , other .shape )
@@ -514,7 +484,7 @@ protected boolean doEquals(AbstractGeometryQueryBuilder other) {
514
484
@ Override
515
485
protected int doHashCode () {
516
486
return Objects .hash (fieldName , indexedShapeId , indexedShapeIndex ,
517
- indexedShapePath , indexedShapeType , indexedShapeRouting , relation , shape , ignoreUnmapped , supplier );
487
+ indexedShapePath , indexedShapeRouting , relation , shape , ignoreUnmapped , supplier );
518
488
}
519
489
520
490
@ Override
@@ -524,19 +494,14 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws
524
494
} else if (this .shape == null ) {
525
495
SetOnce <Geometry > supplier = new SetOnce <>();
526
496
queryRewriteContext .registerAsyncAction ((client , listener ) -> {
527
- GetRequest getRequest ;
528
- if (indexedShapeType == null ) {
529
- getRequest = new GetRequest (indexedShapeIndex , indexedShapeId );
530
- } else {
531
- getRequest = new GetRequest (indexedShapeIndex , indexedShapeId );
532
- }
497
+ GetRequest getRequest = new GetRequest (indexedShapeIndex , indexedShapeId );
533
498
getRequest .routing (indexedShapeRouting );
534
499
fetch (client , getRequest , indexedShapePath , ActionListener .wrap (builder -> {
535
500
supplier .set (builder );
536
501
listener .onResponse (null );
537
502
}, listener ::onFailure ));
538
503
});
539
- return newShapeQueryBuilder (this .fieldName , supplier ::get , this .indexedShapeId , this . indexedShapeType ).relation (relation );
504
+ return newShapeQueryBuilder (this .fieldName , supplier ::get , this .indexedShapeId ).relation (relation );
540
505
}
541
506
return this ;
542
507
}
@@ -548,7 +513,6 @@ protected abstract static class ParsedGeometryQueryParams {
548
513
public ShapeBuilder shape ;
549
514
550
515
public String id = null ;
551
- public String type = null ;
552
516
public String index = null ;
553
517
public String shapePath = null ;
554
518
public String shapeRouting = null ;
@@ -592,8 +556,6 @@ public static ParsedGeometryQueryParams parsedParamsFromXContent(XContentParser
592
556
} else if (token .isValue ()) {
593
557
if (SHAPE_ID_FIELD .match (currentFieldName , parser .getDeprecationHandler ())) {
594
558
params .id = parser .text ();
595
- } else if (SHAPE_TYPE_FIELD .match (currentFieldName , parser .getDeprecationHandler ())) {
596
- params .type = parser .text ();
597
559
} else if (SHAPE_INDEX_FIELD .match (currentFieldName , parser .getDeprecationHandler ())) {
598
560
params .index = parser .text ();
599
561
} else if (SHAPE_PATH_FIELD .match (currentFieldName , parser .getDeprecationHandler ())) {
0 commit comments