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 (#78153) (#77881)
  • Loading branch information
iverase committed Sep 22, 2021
1 parent b100467 commit 20a5006
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
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 @@ -366,6 +367,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 20a5006

Please sign in to comment.