Fix AIOOB on indexed geo_shape query (#28458)
This change fixes a possible AIOOB during the parsing of the document that contains the indexed shape. This change ensures that the parsing does not continue when the field that contains the shape has been found. Closes #28456
This commit is contained in:
parent
9bada306dc
commit
c7d5a54b42
|
@ -409,6 +409,7 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuil
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
if (++currentPathSlot == pathElements.length) {
|
if (++currentPathSlot == pathElements.length) {
|
||||||
listener.onResponse(ShapeParser.parse(parser));
|
listener.onResponse(ShapeParser.parse(parser));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
|
|
|
@ -119,6 +119,7 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
|
||||||
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
|
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
builder.field(expectedShapePath, indexedShapeToReturn);
|
builder.field(expectedShapePath, indexedShapeToReturn);
|
||||||
|
builder.field(randomAlphaOfLengthBetween(10, 20), "something");
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
json = builder.string();
|
json = builder.string();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
@ -227,13 +228,7 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void testMustRewrite() throws IOException {
|
public void testMustRewrite() throws IOException {
|
||||||
GeoShapeQueryBuilder sqb;
|
GeoShapeQueryBuilder query = doCreateTestQueryBuilder(true);
|
||||||
do {
|
|
||||||
sqb = doCreateTestQueryBuilder();
|
|
||||||
// do this until we get one without a shape
|
|
||||||
} while (sqb.shape() != null);
|
|
||||||
|
|
||||||
GeoShapeQueryBuilder query = sqb;
|
|
||||||
|
|
||||||
UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class, () -> query.toQuery(createShardContext()));
|
UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class, () -> query.toQuery(createShardContext()));
|
||||||
assertEquals("query must be rewritten first", e.getMessage());
|
assertEquals("query must be rewritten first", e.getMessage());
|
||||||
|
@ -244,6 +239,23 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
|
||||||
assertEquals(geoShapeQueryBuilder, rewrite);
|
assertEquals(geoShapeQueryBuilder, rewrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testMultipleRewrite() throws IOException {
|
||||||
|
GeoShapeQueryBuilder shape = doCreateTestQueryBuilder(true);
|
||||||
|
QueryBuilder builder = new BoolQueryBuilder()
|
||||||
|
.should(shape)
|
||||||
|
.should(shape);
|
||||||
|
|
||||||
|
builder = rewriteAndFetch(builder, createShardContext());
|
||||||
|
|
||||||
|
GeoShapeQueryBuilder expectedShape = new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, indexedShapeToReturn);
|
||||||
|
expectedShape.strategy(shape.strategy());
|
||||||
|
expectedShape.relation(shape.relation());
|
||||||
|
QueryBuilder expected = new BoolQueryBuilder()
|
||||||
|
.should(expectedShape)
|
||||||
|
.should(expectedShape);
|
||||||
|
assertEquals(expected, builder);
|
||||||
|
}
|
||||||
|
|
||||||
public void testIgnoreUnmapped() throws IOException {
|
public void testIgnoreUnmapped() throws IOException {
|
||||||
ShapeType shapeType = ShapeType.randomType(random());
|
ShapeType shapeType = ShapeType.randomType(random());
|
||||||
ShapeBuilder shape = RandomShapeGenerator.createShapeWithin(random(), null, shapeType);
|
ShapeBuilder shape = RandomShapeGenerator.createShapeWithin(random(), null, shapeType);
|
||||||
|
|
Loading…
Reference in New Issue