Provide better error when updating geo_shape field mapper settings (#47281) (#47338)

This commit is contained in:
Ignacio Vera 2019-10-01 10:52:39 +02:00 committed by GitHub
parent 7d9c064218
commit 03d717dc32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 0 deletions

View File

@ -104,6 +104,17 @@ public class GeoShapeFieldMapper extends AbstractGeometryFieldMapper<Geometry, G
multiFields, copyTo); multiFields, copyTo);
} }
@Override
protected void doMerge(Mapper mergeWith) {
if (mergeWith instanceof LegacyGeoShapeFieldMapper) {
LegacyGeoShapeFieldMapper legacy = (LegacyGeoShapeFieldMapper) mergeWith;
throw new IllegalArgumentException("[" + fieldType().name() + "] with field mapper [" + fieldType().typeName() + "] " +
"using [BKD] strategy cannot be merged with " + "[" + legacy.fieldType().typeName() + "] with [" +
legacy.fieldType().strategy() + "] strategy");
}
super.doMerge(mergeWith);
}
@Override @Override
public GeoShapeFieldType fieldType() { public GeoShapeFieldType fieldType() {
return (GeoShapeFieldType) super.fieldType(); return (GeoShapeFieldType) super.fieldType();

View File

@ -536,6 +536,17 @@ public class LegacyGeoShapeFieldMapper extends AbstractGeometryFieldMapper<Shape
} }
} }
@Override
protected void doMerge(Mapper mergeWith) {
if (mergeWith instanceof GeoShapeFieldMapper) {
GeoShapeFieldMapper fieldMapper = (GeoShapeFieldMapper) mergeWith;
throw new IllegalArgumentException("[" + fieldType().name() + "] with field mapper [" + fieldType().typeName() + "] " +
"using [" + fieldType().strategy() + "] strategy cannot be merged with " + "[" + fieldMapper.typeName() +
"] with [BKD] strategy");
}
super.doMerge(mergeWith);
}
@Override @Override
protected String contentType() { protected String contentType() {
return CONTENT_TYPE; return CONTENT_TYPE;

View File

@ -35,6 +35,7 @@ import org.elasticsearch.test.ESIntegTestCase;
import static org.elasticsearch.index.query.QueryBuilders.geoShapeQuery; import static org.elasticsearch.index.query.QueryBuilders.geoShapeQuery;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
@ -123,6 +124,27 @@ public class GeoShapeIntegrationIT extends ESIntegTestCase {
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
} }
public void testMappingUpdate() throws Exception {
// create index
assertAcked(client().admin().indices().prepareCreate("test")
.addMapping("geometry", "shape", "type=geo_shape").get());
ensureGreen();
String update ="{\n" +
" \"properties\": {\n" +
" \"shape\": {\n" +
" \"type\": \"geo_shape\",\n" +
" \"strategy\": \"recursive\"\n" +
" }\n" +
" }\n" +
"}";
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> client().admin().indices()
.preparePutMapping("test").setType("geometry")
.setSource(update, XContentType.JSON).get());
assertThat(e.getMessage(), containsString("using [BKD] strategy cannot be merged with"));
}
/** /**
* Test that the indexed shape routing can be provided if it is required * Test that the indexed shape routing can be provided if it is required
*/ */