Skip to content

Commit 6983f9a

Browse files
authored
Address shape query builders testToQuery failures (#119096)
With broadening of index versions tested in AbstractQueryBuilder, we need to restore compatibility with 7x index versions that has been removed. Closes #119090 Closes #119091
1 parent 0a7d50d commit 6983f9a

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,6 @@ tests:
302302
issue: https://github.com/elastic/elasticsearch/issues/118414
303303
- class: org.elasticsearch.xpack.esql.qa.multi_node.EsqlClientYamlIT
304304
issue: https://github.com/elastic/elasticsearch/issues/119086
305-
- class: org.elasticsearch.xpack.spatial.index.query.ShapeQueryBuilderOverShapeTests
306-
method: testToQuery
307-
issue: https://github.com/elastic/elasticsearch/issues/119090
308-
- class: org.elasticsearch.xpack.spatial.index.query.GeoShapeQueryBuilderGeoShapeTests
309-
method: testToQuery
310-
issue: https://github.com/elastic/elasticsearch/issues/119091
311305

312306
# Examples:
313307
#

x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/query/GeoShapeQueryBuilderGeoShapeTests.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.geo.GeometryTestUtils;
1414
import org.elasticsearch.geometry.Geometry;
1515
import org.elasticsearch.geometry.ShapeType;
16+
import org.elasticsearch.index.IndexVersions;
1617
import org.elasticsearch.index.mapper.MapperService;
1718
import org.elasticsearch.index.query.GeoShapeQueryBuilder;
1819
import org.elasticsearch.index.query.SearchExecutionContext;
@@ -87,15 +88,27 @@ protected GeoShapeQueryBuilder doCreateTestQueryBuilder(boolean indexedShape) {
8788
}
8889
if (ESTestCase.randomBoolean()) {
8990
SearchExecutionContext context = AbstractBuilderTestCase.createSearchExecutionContext();
90-
if (shapeType == ShapeType.LINESTRING || shapeType == ShapeType.MULTILINESTRING) {
91-
builder.relation(ESTestCase.randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.CONTAINS));
91+
if (context.indexVersionCreated().onOrAfter(IndexVersions.V_7_5_0)) { // CONTAINS is only supported from version 7.5
92+
if (shapeType == ShapeType.LINESTRING || shapeType == ShapeType.MULTILINESTRING) {
93+
builder.relation(ESTestCase.randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.CONTAINS));
94+
} else {
95+
builder.relation(
96+
ESTestCase.randomFrom(
97+
ShapeRelation.DISJOINT,
98+
ShapeRelation.INTERSECTS,
99+
ShapeRelation.WITHIN,
100+
ShapeRelation.CONTAINS
101+
)
102+
);
103+
}
92104
} else {
93-
builder.relation(
94-
ESTestCase.randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.WITHIN, ShapeRelation.CONTAINS)
95-
);
105+
if (shapeType == ShapeType.LINESTRING || shapeType == ShapeType.MULTILINESTRING) {
106+
builder.relation(ESTestCase.randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS));
107+
} else {
108+
builder.relation(ESTestCase.randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.WITHIN));
109+
}
96110
}
97111
}
98-
99112
if (ESTestCase.randomBoolean()) {
100113
builder.ignoreUnmapped(ESTestCase.randomBoolean());
101114
}

x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/query/ShapeQueryBuilderOverShapeTests.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.geo.ShapeTestUtils;
1414
import org.elasticsearch.geometry.Geometry;
1515
import org.elasticsearch.geometry.ShapeType;
16+
import org.elasticsearch.index.IndexVersions;
1617
import org.elasticsearch.index.mapper.MapperService;
1718
import org.elasticsearch.index.query.SearchExecutionContext;
1819

@@ -32,10 +33,18 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws
3233
@Override
3334
protected ShapeRelation getShapeRelation(ShapeType type) {
3435
SearchExecutionContext context = createSearchExecutionContext();
35-
if (type == ShapeType.LINESTRING || type == ShapeType.MULTILINESTRING) {
36-
return randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.CONTAINS);
36+
if (context.indexVersionCreated().onOrAfter(IndexVersions.V_7_5_0)) { // CONTAINS is only supported from version 7.5
37+
if (type == ShapeType.LINESTRING || type == ShapeType.MULTILINESTRING) {
38+
return randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.CONTAINS);
39+
} else {
40+
return randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.WITHIN, ShapeRelation.CONTAINS);
41+
}
3742
} else {
38-
return randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.WITHIN, ShapeRelation.CONTAINS);
43+
if (type == ShapeType.LINESTRING || type == ShapeType.MULTILINESTRING) {
44+
return randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS);
45+
} else {
46+
return randomFrom(ShapeRelation.DISJOINT, ShapeRelation.INTERSECTS, ShapeRelation.WITHIN);
47+
}
3948
}
4049
}
4150

0 commit comments

Comments
 (0)