Skip to content

Commit 0ed05a9

Browse files
authored
Remove types from GeoShapeQueryBuilder (#47792)
This commit removes the unused 'shapeType' information from AbstractGeoQueryBuilder and its implementations. Related to #41059
1 parent 36b03a2 commit 0ed05a9

File tree

6 files changed

+49
-139
lines changed

6 files changed

+49
-139
lines changed

server/src/main/java/org/elasticsearch/index/query/AbstractGeometryQueryBuilder.java

Lines changed: 26 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
import org.apache.lucene.search.MatchNoDocsQuery;
2323
import org.apache.lucene.search.Query;
2424
import org.apache.lucene.util.SetOnce;
25+
import org.elasticsearch.Version;
2526
import org.elasticsearch.action.ActionListener;
2627
import org.elasticsearch.action.get.GetRequest;
2728
import org.elasticsearch.action.get.GetResponse;
2829
import org.elasticsearch.client.Client;
29-
import org.elasticsearch.common.Nullable;
3030
import org.elasticsearch.common.ParseField;
3131
import org.elasticsearch.common.ParsingException;
3232
import org.elasticsearch.common.geo.GeoJson;
@@ -43,6 +43,7 @@
4343
import org.elasticsearch.common.xcontent.XContentParser;
4444
import org.elasticsearch.geometry.Geometry;
4545
import org.elasticsearch.index.mapper.MappedFieldType;
46+
import org.elasticsearch.index.mapper.MapperService;
4647

4748
import java.io.IOException;
4849
import java.util.ArrayList;
@@ -55,9 +56,6 @@
5556
*/
5657
public abstract class AbstractGeometryQueryBuilder<QB extends AbstractGeometryQueryBuilder<QB>> extends AbstractQueryBuilder<QB> {
5758

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-
6159
public static final String DEFAULT_SHAPE_INDEX_NAME = "shapes";
6260
public static final String DEFAULT_SHAPE_FIELD_NAME = "shape";
6361
public static final ShapeRelation DEFAULT_SHAPE_RELATION = ShapeRelation.INTERSECTS;
@@ -72,7 +70,6 @@ public abstract class AbstractGeometryQueryBuilder<QB extends AbstractGeometryQu
7270
protected static final ParseField RELATION_FIELD = new ParseField("relation");
7371
protected static final ParseField INDEXED_SHAPE_FIELD = new ParseField("indexed_shape");
7472
protected static final ParseField SHAPE_ID_FIELD = new ParseField("id");
75-
protected static final ParseField SHAPE_TYPE_FIELD = new ParseField("type");
7673
protected static final ParseField SHAPE_INDEX_FIELD = new ParseField("index");
7774
protected static final ParseField SHAPE_PATH_FIELD = new ParseField("path");
7875
protected static final ParseField SHAPE_ROUTING_FIELD = new ParseField("routing");
@@ -82,7 +79,6 @@ public abstract class AbstractGeometryQueryBuilder<QB extends AbstractGeometryQu
8279
protected final Supplier<Geometry> supplier;
8380

8481
protected final String indexedShapeId;
85-
protected final String indexedShapeType;
8682

8783
protected Geometry shape;
8884
protected String indexedShapeIndex = DEFAULT_SHAPE_INDEX_NAME;
@@ -105,7 +101,7 @@ public abstract class AbstractGeometryQueryBuilder<QB extends AbstractGeometryQu
105101
*/
106102
@Deprecated
107103
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);
109105
}
110106

111107
/**
@@ -118,7 +114,7 @@ protected AbstractGeometryQueryBuilder(String fieldName, ShapeBuilder shape) {
118114
* Shape used in the Query
119115
*/
120116
public AbstractGeometryQueryBuilder(String fieldName, Geometry shape) {
121-
this(fieldName, shape, null, null);
117+
this(fieldName, shape, null);
122118
}
123119

124120
/**
@@ -131,28 +127,10 @@ public AbstractGeometryQueryBuilder(String fieldName, Geometry shape) {
131127
* ID of the indexed Shape that will be used in the Query
132128
*/
133129
protected AbstractGeometryQueryBuilder(String fieldName, String indexedShapeId) {
134-
this(fieldName, (Geometry) null, indexedShapeId, null);
130+
this(fieldName, (Geometry) null, indexedShapeId);
135131
}
136132

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) {
156134
if (fieldName == null) {
157135
throw new IllegalArgumentException("fieldName is required");
158136
}
@@ -162,17 +140,20 @@ protected AbstractGeometryQueryBuilder(String fieldName, Geometry shape, String
162140
this.fieldName = fieldName;
163141
this.shape = shape;
164142
this.indexedShapeId = indexedShapeId;
165-
this.indexedShapeType = indexedShapeType;
166143
this.supplier = null;
167144
}
168145

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+
}
171153
this.fieldName = fieldName;
172154
this.shape = null;
173155
this.supplier = supplier;
174-
this.indexedShapeId = indexedShapeId;
175-
this.indexedShapeType = indexedShapeType;
156+
this.indexedShapeId = indexedShapeId;;
176157
}
177158

178159
/**
@@ -184,11 +165,13 @@ protected AbstractGeometryQueryBuilder(StreamInput in) throws IOException {
184165
if (in.readBoolean()) {
185166
shape = GeometryIO.readGeometry(in);
186167
indexedShapeId = null;
187-
indexedShapeType = null;
188168
} else {
189169
shape = null;
190170
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+
}
192175
indexedShapeIndex = in.readOptionalString();
193176
indexedShapePath = in.readOptionalString();
194177
indexedShapeRouting = in.readOptionalString();
@@ -210,7 +193,9 @@ protected void doWriteTo(StreamOutput out) throws IOException {
210193
GeometryIO.writeGeometry(out, shape);
211194
} else {
212195
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+
}
214199
out.writeOptionalString(indexedShapeIndex);
215200
out.writeOptionalString(indexedShapePath);
216201
out.writeOptionalString(indexedShapeRouting);
@@ -254,17 +239,6 @@ public String indexedShapeId() {
254239
return indexedShapeId;
255240
}
256241

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-
268242
/**
269243
* Sets the name of the index where the indexed Shape can be found
270244
*
@@ -372,9 +346,9 @@ public boolean ignoreUnmapped() {
372346
protected abstract void doShapeQueryXContent(XContentBuilder builder, Params params) throws IOException;
373347
/** creates a new ShapeQueryBuilder from the provided field name and shape builder */
374348
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*/
376350
protected abstract AbstractGeometryQueryBuilder<QB> newShapeQueryBuilder(String fieldName, Supplier<Geometry> shapeSupplier,
377-
String indexedShapeId, String indexedShapeType);
351+
String indexedShapeId);
378352

379353
/** returns true if the provided field type is valid for this query */
380354
protected boolean isValidContentType(String typeName) {
@@ -469,9 +443,6 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
469443
} else {
470444
builder.startObject(INDEXED_SHAPE_FIELD.getPreferredName())
471445
.field(SHAPE_ID_FIELD.getPreferredName(), indexedShapeId);
472-
if (indexedShapeType != null) {
473-
builder.field(SHAPE_TYPE_FIELD.getPreferredName(), indexedShapeType);
474-
}
475446
if (indexedShapeIndex != null) {
476447
builder.field(SHAPE_INDEX_FIELD.getPreferredName(), indexedShapeIndex);
477448
}
@@ -503,7 +474,6 @@ protected boolean doEquals(AbstractGeometryQueryBuilder other) {
503474
&& Objects.equals(indexedShapeId, other.indexedShapeId)
504475
&& Objects.equals(indexedShapeIndex, other.indexedShapeIndex)
505476
&& Objects.equals(indexedShapePath, other.indexedShapePath)
506-
&& Objects.equals(indexedShapeType, other.indexedShapeType)
507477
&& Objects.equals(indexedShapeRouting, other.indexedShapeRouting)
508478
&& Objects.equals(relation, other.relation)
509479
&& Objects.equals(shape, other.shape)
@@ -514,7 +484,7 @@ protected boolean doEquals(AbstractGeometryQueryBuilder other) {
514484
@Override
515485
protected int doHashCode() {
516486
return Objects.hash(fieldName, indexedShapeId, indexedShapeIndex,
517-
indexedShapePath, indexedShapeType, indexedShapeRouting, relation, shape, ignoreUnmapped, supplier);
487+
indexedShapePath, indexedShapeRouting, relation, shape, ignoreUnmapped, supplier);
518488
}
519489

520490
@Override
@@ -524,19 +494,14 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws
524494
} else if (this.shape == null) {
525495
SetOnce<Geometry> supplier = new SetOnce<>();
526496
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);
533498
getRequest.routing(indexedShapeRouting);
534499
fetch(client, getRequest, indexedShapePath, ActionListener.wrap(builder-> {
535500
supplier.set(builder);
536501
listener.onResponse(null);
537502
}, listener::onFailure));
538503
});
539-
return newShapeQueryBuilder(this.fieldName, supplier::get, this.indexedShapeId, this.indexedShapeType).relation(relation);
504+
return newShapeQueryBuilder(this.fieldName, supplier::get, this.indexedShapeId).relation(relation);
540505
}
541506
return this;
542507
}
@@ -548,7 +513,6 @@ protected abstract static class ParsedGeometryQueryParams {
548513
public ShapeBuilder shape;
549514

550515
public String id = null;
551-
public String type = null;
552516
public String index = null;
553517
public String shapePath = null;
554518
public String shapeRouting = null;
@@ -592,8 +556,6 @@ public static ParsedGeometryQueryParams parsedParamsFromXContent(XContentParser
592556
} else if (token.isValue()) {
593557
if (SHAPE_ID_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
594558
params.id = parser.text();
595-
} else if (SHAPE_TYPE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
596-
params.type = parser.text();
597559
} else if (SHAPE_INDEX_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
598560
params.index = parser.text();
599561
} else if (SHAPE_PATH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {

server/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.apache.logging.log4j.LogManager;
2323
import org.apache.lucene.search.ConstantScoreQuery;
2424
import org.apache.lucene.search.Query;
25-
import org.elasticsearch.common.Nullable;
2625
import org.elasticsearch.common.ParseField;
2726
import org.elasticsearch.common.ParsingException;
2827
import org.elasticsearch.common.geo.ShapeRelation;
@@ -86,27 +85,15 @@ public GeoShapeQueryBuilder(String fieldName, ShapeBuilder shape) {
8685
super(fieldName, shape);
8786
}
8887

89-
public GeoShapeQueryBuilder(String fieldName, Supplier<Geometry> shapeSupplier, String indexedShapeId,
90-
@Nullable String indexedShapeType) {
91-
super(fieldName, shapeSupplier, indexedShapeId, indexedShapeType);
92-
}
93-
9488
/**
9589
* Creates a new GeoShapeQueryBuilder whose Query will be against the given
96-
* field name and will use the Shape found with the given ID in the given
97-
* type
98-
*
99-
* @param fieldName
100-
* Name of the field that will be filtered
101-
* @param indexedShapeId
102-
* ID of the indexed Shape that will be used in the Query
103-
* @param indexedShapeType
104-
* Index type of the indexed Shapes
105-
* @deprecated use {@link #GeoShapeQueryBuilder(String, String)} instead
90+
* field name and will use the Shape found with the given shape id and supplier
91+
* @param fieldName Name of the field that will be queried
92+
* @param shapeSupplier A shape supplier
93+
* @param indexedShapeId The indexed id of a shape
10694
*/
107-
@Deprecated
108-
public GeoShapeQueryBuilder(String fieldName, String indexedShapeId, String indexedShapeType) {
109-
super(fieldName, indexedShapeId, indexedShapeType);
95+
public GeoShapeQueryBuilder(String fieldName, Supplier<Geometry> shapeSupplier, String indexedShapeId) {
96+
super(fieldName, shapeSupplier, indexedShapeId);
11097
}
11198

11299
/**
@@ -204,8 +191,8 @@ protected GeoShapeQueryBuilder newShapeQueryBuilder(String fieldName, Geometry s
204191

205192
@Override
206193
protected GeoShapeQueryBuilder newShapeQueryBuilder(String fieldName, Supplier<Geometry> shapeSupplier,
207-
String indexedShapeId, String indexedShapeType) {
208-
return new GeoShapeQueryBuilder(fieldName, shapeSupplier, indexedShapeId, indexedShapeType);
194+
String indexedShapeId) {
195+
return new GeoShapeQueryBuilder(fieldName, shapeSupplier, indexedShapeId);
209196
}
210197

211198
@Override
@@ -265,14 +252,11 @@ public static GeoShapeQueryBuilder fromXContent(XContentParser parser) throws IO
265252
(ParsedGeoShapeQueryParams) AbstractGeometryQueryBuilder.parsedParamsFromXContent(parser, new ParsedGeoShapeQueryParams());
266253

267254
GeoShapeQueryBuilder builder;
268-
if (pgsqp.type != null) {
269-
deprecationLogger.deprecatedAndMaybeLog("geo_share_query_with_types", TYPES_DEPRECATION_MESSAGE);
270-
}
271255

272256
if (pgsqp.shape != null) {
273257
builder = new GeoShapeQueryBuilder(pgsqp.fieldName, pgsqp.shape);
274258
} else {
275-
builder = new GeoShapeQueryBuilder(pgsqp.fieldName, pgsqp.id, pgsqp.type);
259+
builder = new GeoShapeQueryBuilder(pgsqp.fieldName, pgsqp.id);
276260
}
277261

278262
if (pgsqp.index != null) {

server/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQueryBuilder> {
5858

5959
protected static String indexedShapeId;
60-
protected static String indexedShapeType;
6160
protected static String indexedShapePath;
6261
protected static String indexedShapeIndex;
6362
protected static String indexedShapeRouting;
@@ -94,8 +93,7 @@ protected GeoShapeQueryBuilder doCreateTestQueryBuilder(boolean indexedShape) {
9493
} else {
9594
indexedShapeToReturn = shape;
9695
indexedShapeId = randomAlphaOfLengthBetween(3, 20);
97-
indexedShapeType = randomBoolean() ? randomAlphaOfLengthBetween(3, 20) : null;
98-
builder = new GeoShapeQueryBuilder(fieldName(), indexedShapeId, indexedShapeType);
96+
builder = new GeoShapeQueryBuilder(fieldName(), indexedShapeId);
9997
if (randomBoolean()) {
10098
indexedShapeIndex = randomAlphaOfLengthBetween(3, 20);
10199
builder.indexedShapeIndex(indexedShapeIndex);
@@ -154,7 +152,6 @@ protected GetResponse executeGet(GetRequest getRequest) {
154152
public void clearShapeFields() {
155153
indexedShapeToReturn = null;
156154
indexedShapeId = null;
157-
indexedShapeType = null;
158155
indexedShapePath = null;
159156
indexedShapeIndex = null;
160157
indexedShapeRouting = null;
@@ -181,7 +178,7 @@ public void testNoShape() throws IOException {
181178

182179
public void testNoIndexedShape() throws IOException {
183180
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
184-
() -> new GeoShapeQueryBuilder(fieldName(), null, "type"));
181+
() -> new GeoShapeQueryBuilder(fieldName(), null, null));
185182
assertEquals("either shape or indexedShapeId is required", e.getMessage());
186183
}
187184

@@ -297,11 +294,6 @@ public void testSerializationFailsUnlessFetched() throws IOException {
297294
protected QueryBuilder parseQuery(XContentParser parser) throws IOException {
298295
QueryBuilder query = super.parseQuery(parser);
299296
assertThat(query, instanceOf(GeoShapeQueryBuilder.class));
300-
301-
GeoShapeQueryBuilder shapeQuery = (GeoShapeQueryBuilder) query;
302-
if (shapeQuery.indexedShapeType() != null) {
303-
assertWarnings(GeoShapeQueryBuilder.TYPES_DEPRECATION_MESSAGE);
304-
}
305297
return query;
306298
}
307299
}

0 commit comments

Comments
 (0)