-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
disallow creating geo_shape mappings with deprecated parameters #70850
Changes from 1 commit
edfd032
40ad9bc
d707cf0
ab9063e
82995d1
4b4a5e3
44edae5
1b5ecf8
ff7fd85
6d66d6a
e93344b
4f3a451
75b827d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -452,6 +452,10 @@ public LegacyGeoShapeFieldMapper(String simpleName, MappedFieldType mappedFieldT | |
super(simpleName, mappedFieldType, Collections.singletonMap(mappedFieldType.name(), Lucene.KEYWORD_ANALYZER), | ||
builder.ignoreMalformed.get(), builder.coerce.get(), builder.ignoreZValue.get(), builder.orientation.get(), | ||
multiFields, copyTo, indexer, parser); | ||
if (builder.indexCreatedVersion.onOrAfter(Version.V_8_0_0)) { | ||
throw new IllegalArgumentException("mapper [" + name() | ||
+ "] of type [geo_shape] with deprecated parameters is no longer allowed"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to be a bit clearer about what is causing the error here. Maybe instead of having the version check here we should move it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I have done is to collect the used deprecated parameters in the builder so we can report back to the user. wdyt? |
||
} | ||
this.indexCreatedVersion = builder.indexCreatedVersion; | ||
this.builder = builder; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree; | ||
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree; | ||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.CheckedConsumer; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.geo.GeoUtils; | ||
|
@@ -25,6 +26,7 @@ | |
import org.elasticsearch.index.query.SearchExecutionContext; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin; | ||
import org.elasticsearch.test.VersionUtils; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
|
@@ -98,6 +100,21 @@ protected boolean supportsMeta() { | |
return false; | ||
} | ||
|
||
@Override | ||
protected MapperService createMapperService(XContentBuilder mappings) throws IOException { | ||
Version version = VersionUtils.randomPreviousCompatibleVersion(random(), Version.V_8_0_0); | ||
return createMapperService(version, mappings); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about we also override There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That works too. Implemented. |
||
|
||
public void testInvalidCurrentVersion() { | ||
MapperParsingException e = | ||
expectThrows(MapperParsingException.class, | ||
() -> createMapperService(Version.CURRENT, fieldMapping(this::minimalMapping))); | ||
assertThat(e.getMessage(), | ||
containsString("mapper [field] of type [geo_shape] with deprecated parameters is no longer allowed")); | ||
assertFieldWarnings("strategy"); | ||
} | ||
|
||
public void testLegacySwitches() throws IOException { | ||
// if one of the legacy parameters is added to a 'type':'geo_shape' config then | ||
// that will select the legacy field mapper | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this into the Builder constructor? The earlier we throw the better, in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried but I have issues with this test:
elasticsearch/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperTestCase.java
Line 270 in 91c700b
It seems that checking of unknown parameters happen after the builder.