Skip to content

Commit 84b748c

Browse files
committed
Merge pull request #13963 from javanna/fix/geo_shape_strategy_optional
Make strategy optional in GeoShapeQueryBuilder readFrom and writeTo
2 parents 484ee0a + 7e84053 commit 84b748c

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
7070
// and Equals so ShapeBuilder can be used here
7171
private BytesReference shapeBytes;
7272

73-
private SpatialStrategy strategy = null;
73+
private SpatialStrategy strategy;
7474

7575
private final String indexedShapeId;
7676
private final String indexedShapeType;
@@ -429,7 +429,9 @@ protected GeoShapeQueryBuilder doReadFrom(StreamInput in) throws IOException {
429429
}
430430
}
431431
builder.relation = ShapeRelation.DISJOINT.readFrom(in);
432-
builder.strategy = SpatialStrategy.RECURSIVE.readFrom(in);
432+
if (in.readBoolean()) {
433+
builder.strategy = SpatialStrategy.RECURSIVE.readFrom(in);
434+
}
433435
return builder;
434436
}
435437

@@ -447,7 +449,12 @@ protected void doWriteTo(StreamOutput out) throws IOException {
447449
out.writeOptionalString(indexedShapePath);
448450
}
449451
relation.writeTo(out);
450-
strategy.writeTo(out);
452+
if (strategy == null) {
453+
out.writeBoolean(false);
454+
} else {
455+
out.writeBoolean(true);
456+
strategy.writeTo(out);
457+
}
451458
}
452459

453460
@Override

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ protected GeoShapeQueryBuilder doCreateTestQueryBuilder() {
7777
builder.indexedShapePath(indexedShapePath);
7878
}
7979
}
80-
SpatialStrategy strategy = randomFrom(SpatialStrategy.values());
81-
builder.strategy(strategy);
82-
if (strategy != SpatialStrategy.TERM) {
83-
builder.relation(randomFrom(ShapeRelation.values()));
80+
if (randomBoolean()) {
81+
SpatialStrategy strategy = randomFrom(SpatialStrategy.values());
82+
builder.strategy(strategy);
83+
if (strategy != SpatialStrategy.TERM) {
84+
builder.relation(randomFrom(ShapeRelation.values()));
85+
}
8486
}
8587
return builder;
8688
}
@@ -105,9 +107,7 @@ protected GetResponse executeGet(GetRequest getRequest) {
105107
} catch (IOException ex) {
106108
throw new ElasticsearchException("boom", ex);
107109
}
108-
GetResponse response = new GetResponse(new GetResult(indexedShapeIndex, indexedShapeType, indexedShapeId, 0, true, new BytesArray(
109-
json), null));
110-
return response;
110+
return new GetResponse(new GetResult(indexedShapeIndex, indexedShapeType, indexedShapeId, 0, true, new BytesArray(json), null));
111111
}
112112

113113
@After
@@ -149,7 +149,7 @@ public void testNoFieldName() throws Exception {
149149
@Test
150150
public void testNoShape() throws IOException {
151151
try {
152-
GeoShapeQueryBuilder builder = new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, (ShapeBuilder) null);
152+
new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, (ShapeBuilder) null);
153153
fail("exception expected");
154154
} catch (IllegalArgumentException e) {
155155
// expected
@@ -158,12 +158,12 @@ public void testNoShape() throws IOException {
158158

159159
@Test(expected = IllegalArgumentException.class)
160160
public void testNoIndexedShape() throws IOException {
161-
new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, (String) null, "type");
161+
new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, null, "type");
162162
}
163163

164164
@Test(expected = IllegalArgumentException.class)
165165
public void testNoIndexedShapeType() throws IOException {
166-
new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, "id", (String) null);
166+
new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, "id", null);
167167
}
168168

169169
@Test(expected=IllegalArgumentException.class)

0 commit comments

Comments
 (0)