Skip to content

Commit

Permalink
geo_shape mapping created before version 6.6.0 should be using the le…
Browse files Browse the repository at this point in the history
…gacy mapper (#77881)

old mappings previous to version 6.6 should always be using the legacy mapper.
  • Loading branch information
iverase authored Sep 22, 2021
1 parent dfc9a8e commit 9125cb8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
import org.apache.lucene.search.Query;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.Version;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.geo.GeoUtils;
import org.elasticsearch.geo.GeometryTestUtils;
import org.elasticsearch.geometry.Rectangle;
import org.elasticsearch.geometry.utils.Geohash;
import org.elasticsearch.index.mapper.GeoPointFieldMapper;
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.test.AbstractQueryTestCase;

Expand Down Expand Up @@ -222,11 +220,7 @@ protected void doAssertLuceneQuery(GeoBoundingBoxQueryBuilder queryBuilder, Quer
queryBuilder.topLeft().lon(),
queryBuilder.bottomRight().lon()), dvQuery);
} else {
if (context.indexVersionCreated().before(Version.V_6_6_0)) {
assertEquals(LegacyGeoShapeFieldMapper.GeoShapeFieldType.class, fieldType.getClass());
} else {
assertEquals(GeoShapeFieldMapper.GeoShapeFieldType.class, fieldType.getClass());
}
assertEquals(GeoShapeFieldMapper.GeoShapeFieldType.class, fieldType.getClass());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@
import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.Version;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.geo.GeoDistance;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.geo.GeometryTestUtils;
import org.elasticsearch.index.mapper.GeoPointFieldMapper;
import org.elasticsearch.index.mapper.GeoShapeFieldMapper;
import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.test.AbstractQueryTestCase;

Expand All @@ -32,7 +29,6 @@
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;

@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/77857")
public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDistanceQueryBuilder> {

@Override
Expand Down Expand Up @@ -140,11 +136,7 @@ protected void doAssertLuceneQuery(GeoDistanceQueryBuilder queryBuilder, Query q
queryBuilder.distance()),
dvQuery);
} else {
if (context.indexVersionCreated().before(Version.V_6_6_0)) {
assertEquals(LegacyGeoShapeFieldMapper.GeoShapeFieldType.class, fieldType.getClass());
} else {
assertEquals(GeoShapeFieldMapper.GeoShapeFieldType.class, fieldType.getClass());
}
assertEquals(GeoShapeFieldMapper.GeoShapeFieldType.class, fieldType.getClass());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ public Mapper.Builder parse(String name, Map<String, Object> node, MappingParser
FieldMapper.Builder builder;
boolean ignoreMalformedByDefault = IGNORE_MALFORMED_SETTING.get(parserContext.getSettings());
boolean coerceByDefault = COERCE_SETTING.get(parserContext.getSettings());
if (LegacyGeoShapeFieldMapper.containsDeprecatedParameter(node.keySet())) {
if (parserContext.indexVersionCreated().before(Version.V_6_6_0) ||
LegacyGeoShapeFieldMapper.containsDeprecatedParameter(node.keySet())) {
builder = new LegacyGeoShapeFieldMapper.Builder(
name,
parserContext.indexVersionCreated(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
Expand Down Expand Up @@ -391,6 +392,17 @@ public void testMultiFieldsDeprecationWarning() throws Exception {
assertWarnings("Adding multifields to [geo_shape] mappers has no effect and will be forbidden in future");
}

public void testRandomVersionMapping() throws Exception {
Version version = VersionUtils.randomIndexCompatibleVersion(random());
DocumentMapper defaultMapper = createDocumentMapper(version, fieldMapping(this::minimalMapping));
Mapper fieldMapper = defaultMapper.mappers().getMapper("field");
if (version.before(Version.V_6_6_0)) {
assertThat(fieldMapper, instanceOf(LegacyGeoShapeFieldMapper.class));
} else {
assertThat(fieldMapper, instanceOf(GeoShapeWithDocValuesFieldMapper.class));
}
}

public String toXContentString(GeoShapeWithDocValuesFieldMapper mapper, boolean includeDefaults) {
if (includeDefaults) {
ToXContent.Params params = new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.Query;
import org.elasticsearch.Version;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand Down Expand Up @@ -41,7 +42,8 @@ protected Collection<Class<? extends Plugin>> getPlugins() {

@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
if (randomBoolean()) {

if (mapperService.parserContext().indexVersionCreated().before(Version.V_6_6_0) || randomBoolean()) {
XContentBuilder mapping = jsonBuilder().startObject().startObject("_doc").startObject("properties")
.startObject("test").field("type", "geo_shape").endObject().endObject().endObject().endObject();
mapperService.merge("_doc",
Expand Down

0 comments on commit 9125cb8

Please sign in to comment.