Skip to content

Commit 874bf7b

Browse files
authored
Replace LegacyGeoShapeWithDocValuesIT with unit tests (#120266)
This change removes LegacyGeoShapeWithDocValuesIT which contains two specific test for legacy "geo_shape" mappings that can still be used in version 7 indices. The functionality checked in covered by "testMappingUpdate" should be covered by GeoShapeWithDocValuesFieldMapperTests#testGeoShapeLegacyMerge already, the test with a Circle shape is moved to GeoShapeWithDocValuesFieldMapperTests.
1 parent 28dde91 commit 874bf7b

File tree

2 files changed

+40
-109
lines changed

2 files changed

+40
-109
lines changed

x-pack/plugin/spatial/src/internalClusterTest/java/org/elasticsearch/xpack/spatial/search/LegacyGeoShapeWithDocValuesIT.java

Lines changed: 0 additions & 109 deletions
This file was deleted.

x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapperTests.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
*/
77
package org.elasticsearch.xpack.spatial.index.mapper;
88

9+
import org.apache.lucene.index.DirectoryReader;
910
import org.apache.lucene.index.IndexableField;
11+
import org.apache.lucene.search.TopDocs;
12+
import org.apache.lucene.search.TotalHits;
13+
import org.apache.lucene.store.Directory;
14+
import org.apache.lucene.tests.index.RandomIndexWriter;
1015
import org.apache.lucene.util.BytesRef;
1116
import org.elasticsearch.common.Strings;
1217
import org.elasticsearch.common.geo.GeoJson;
1318
import org.elasticsearch.common.geo.Orientation;
1419
import org.elasticsearch.common.geo.ShapeRelation;
1520
import org.elasticsearch.common.geo.SpatialStrategy;
1621
import org.elasticsearch.geo.GeometryTestUtils;
22+
import org.elasticsearch.geometry.Circle;
1723
import org.elasticsearch.geometry.Geometry;
1824
import org.elasticsearch.geometry.MultiPoint;
1925
import org.elasticsearch.geometry.Point;
@@ -27,12 +33,14 @@
2733
import org.elasticsearch.index.mapper.AbstractShapeGeometryFieldMapper.AbstractShapeGeometryFieldType;
2834
import org.elasticsearch.index.mapper.DocumentMapper;
2935
import org.elasticsearch.index.mapper.DocumentParsingException;
36+
import org.elasticsearch.index.mapper.LuceneDocument;
3037
import org.elasticsearch.index.mapper.MappedFieldType;
3138
import org.elasticsearch.index.mapper.Mapper;
3239
import org.elasticsearch.index.mapper.MapperParsingException;
3340
import org.elasticsearch.index.mapper.MapperService;
3441
import org.elasticsearch.index.mapper.ParsedDocument;
3542
import org.elasticsearch.index.mapper.SourceToParse;
43+
import org.elasticsearch.index.query.GeoShapeQueryBuilder;
3644
import org.elasticsearch.index.query.SearchExecutionContext;
3745
import org.elasticsearch.legacygeo.mapper.LegacyGeoShapeFieldMapper;
3846
import org.elasticsearch.legacygeo.mapper.LegacyGeoShapeFieldMapper.GeoShapeFieldType;
@@ -390,6 +398,38 @@ public void testGeoShapeLegacyMerge() throws Exception {
390398
assertFieldWarnings("strategy");
391399
}
392400

401+
public void testGeoShapeLegacyCircle() throws Exception {
402+
IndexVersion version = IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.V_8_0_0);
403+
MapperService mapperService = createMapperService(version, fieldMapping(b -> {
404+
b.field("type", getFieldName());
405+
b.field("strategy", "recursive");
406+
b.field("tree", "geohash");
407+
}));
408+
assertCriticalWarnings(
409+
"Parameter [strategy] is deprecated and will be removed in a future version",
410+
"Parameter [tree] is deprecated and will be removed in a future version"
411+
);
412+
413+
try (Directory directory = newDirectory()) {
414+
RandomIndexWriter iw = new RandomIndexWriter(random(), directory);
415+
Circle circle = new Circle(30, 50, 77000);
416+
417+
LuceneDocument doc = mapperService.documentMapper().parse(source(b -> {
418+
b.field("field");
419+
GeoJson.toXContent(circle, b, null);
420+
})).rootDoc();
421+
iw.addDocument(doc);
422+
iw.close();
423+
try (DirectoryReader reader = DirectoryReader.open(directory)) {
424+
SearchExecutionContext context = createSearchExecutionContext(mapperService, newSearcher(reader));
425+
GeoShapeQueryBuilder queryBuilder = new GeoShapeQueryBuilder("field", new Circle(30, 50, 77000));
426+
TopDocs docs = context.searcher().search(queryBuilder.toQuery(context), 1);
427+
assertThat(docs.totalHits.value(), equalTo(1L));
428+
assertThat(docs.totalHits.relation(), equalTo(TotalHits.Relation.EQUAL_TO));
429+
}
430+
}
431+
}
432+
393433
private void assertFieldWarnings(String... fieldNames) {
394434
String[] warnings = new String[fieldNames.length];
395435
for (int i = 0; i < fieldNames.length; ++i) {

0 commit comments

Comments
 (0)