|
6 | 6 | */ |
7 | 7 | package org.elasticsearch.xpack.spatial.index.mapper; |
8 | 8 |
|
| 9 | +import org.apache.lucene.index.DirectoryReader; |
9 | 10 | 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; |
10 | 15 | import org.apache.lucene.util.BytesRef; |
11 | 16 | import org.elasticsearch.common.Strings; |
12 | 17 | import org.elasticsearch.common.geo.GeoJson; |
13 | 18 | import org.elasticsearch.common.geo.Orientation; |
14 | 19 | import org.elasticsearch.common.geo.ShapeRelation; |
15 | 20 | import org.elasticsearch.common.geo.SpatialStrategy; |
16 | 21 | import org.elasticsearch.geo.GeometryTestUtils; |
| 22 | +import org.elasticsearch.geometry.Circle; |
17 | 23 | import org.elasticsearch.geometry.Geometry; |
18 | 24 | import org.elasticsearch.geometry.MultiPoint; |
19 | 25 | import org.elasticsearch.geometry.Point; |
|
27 | 33 | import org.elasticsearch.index.mapper.AbstractShapeGeometryFieldMapper.AbstractShapeGeometryFieldType; |
28 | 34 | import org.elasticsearch.index.mapper.DocumentMapper; |
29 | 35 | import org.elasticsearch.index.mapper.DocumentParsingException; |
| 36 | +import org.elasticsearch.index.mapper.LuceneDocument; |
30 | 37 | import org.elasticsearch.index.mapper.MappedFieldType; |
31 | 38 | import org.elasticsearch.index.mapper.Mapper; |
32 | 39 | import org.elasticsearch.index.mapper.MapperParsingException; |
33 | 40 | import org.elasticsearch.index.mapper.MapperService; |
34 | 41 | import org.elasticsearch.index.mapper.ParsedDocument; |
35 | 42 | import org.elasticsearch.index.mapper.SourceToParse; |
| 43 | +import org.elasticsearch.index.query.GeoShapeQueryBuilder; |
36 | 44 | import org.elasticsearch.index.query.SearchExecutionContext; |
37 | 45 | import org.elasticsearch.legacygeo.mapper.LegacyGeoShapeFieldMapper; |
38 | 46 | import org.elasticsearch.legacygeo.mapper.LegacyGeoShapeFieldMapper.GeoShapeFieldType; |
@@ -390,6 +398,38 @@ public void testGeoShapeLegacyMerge() throws Exception { |
390 | 398 | assertFieldWarnings("strategy"); |
391 | 399 | } |
392 | 400 |
|
| 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 | + |
393 | 433 | private void assertFieldWarnings(String... fieldNames) { |
394 | 434 | String[] warnings = new String[fieldNames.length]; |
395 | 435 | for (int i = 0; i < fieldNames.length; ++i) { |
|
0 commit comments