Deprecate the `_default_` mapping. (#25652)

Now that indices cannot have types anymore, this feature does not buy anything
anymore.

Closes #25500
This commit is contained in:
Adrien Grand 2017-07-17 15:37:59 +02:00 committed by GitHub
parent e9aa60dc9d
commit 264088f1c4
10 changed files with 27 additions and 27 deletions

View File

@ -32,6 +32,8 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
@ -104,6 +106,8 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
"_size", "_timestamp", "_ttl"
);
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(MapperService.class));
private final IndexAnalyzers indexAnalyzers;
/**
@ -351,6 +355,11 @@ public class MapperService extends AbstractIndexComponent implements Closeable {
Map<String, DocumentMapper> results = new LinkedHashMap<>(documentMappers.size() + 1);
if (defaultMapper != null) {
if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_6_0_0_beta1)
&& reason == MergeReason.MAPPING_UPDATE) { // only log in case of explicit mapping updates
DEPRECATION_LOGGER.deprecated("[_default_] mapping is deprecated since it is not useful anymore now that indexes " +
"cannot have more than one type");
}
assert defaultMapper.type().equals(DEFAULT_MAPPING);
mappers.put(DEFAULT_MAPPING, defaultMapper);
results.put(DEFAULT_MAPPING, defaultMapper);

View File

@ -331,4 +331,12 @@ public class MapperServiceTests extends ESSingleNodeTestCase {
() -> mapperService.merge("type2", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, randomBoolean()));
assertThat(e.getMessage(), Matchers.startsWith("Rejecting mapping update to [test] as the final mapping would have more than 1 type: "));
}
public void testDefaultMappingIsDeprecated() throws IOException {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("_default_").endObject().endObject().string();
MapperService mapperService = createIndex("test").mapperService();
mapperService.merge("_default_", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, randomBoolean());
assertWarnings("[_default_] mapping is deprecated since it is not useful anymore now that indexes " +
"cannot have more than one type");
}
}

View File

@ -20,8 +20,11 @@
package org.elasticsearch.index.mapper;
import org.apache.lucene.index.IndexableField;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
@ -159,7 +162,8 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
.startObject("_source").field("enabled", false).endObject()
.endObject().endObject().string();
MapperService mapperService = createIndex("test").mapperService();
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_6_0).build();
MapperService mapperService = createIndex("test", settings).mapperService();
mapperService.merge(MapperService.DEFAULT_MAPPING, new CompressedXContent(defaultMapping), MapperService.MergeReason.MAPPING_UPDATE, false);
DocumentMapper mapper = mapperService.documentMapperWithAutoCreate("my_type").getDocumentMapper();
@ -172,7 +176,8 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
.startObject("_source").field("enabled", false).endObject()
.endObject().endObject().string();
MapperService mapperService = createIndex("test").mapperService();
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_6_0).build();
MapperService mapperService = createIndex("test", settings).mapperService();
mapperService.merge(MapperService.DEFAULT_MAPPING, new CompressedXContent(defaultMapping), MapperService.MergeReason.MAPPING_UPDATE, false);
String mapping = XContentFactory.jsonBuilder().startObject().startObject("my_type")

View File

@ -36,7 +36,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.emptyIterable;
@ESIntegTestCase.ClusterScope(randomDynamicTemplates = false) // this test takes a long time to delete the idx if all fields are eager loading
public class ConcurrentDynamicTemplateIT extends ESIntegTestCase {
private final String mappingType = "test-mapping";

View File

@ -44,7 +44,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBloc
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
@ClusterScope(randomDynamicTemplates = false)
public class SimpleGetMappingsIT extends ESIntegTestCase {
@Override

View File

@ -64,7 +64,6 @@ import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
@ClusterScope(randomDynamicTemplates = false)
public class UpdateMappingIntegrationIT extends ESIntegTestCase {
@Override

View File

@ -78,7 +78,7 @@ import static org.hamcrest.Matchers.startsWith;
/**
* Integration tests for InternalCircuitBreakerService
*/
@ClusterScope(scope = TEST, randomDynamicTemplates = false, numClientNodes = 0, maxNumDataNodes = 1)
@ClusterScope(scope = TEST, numClientNodes = 0, maxNumDataNodes = 1)
public class CircuitBreakerServiceIT extends ESIntegTestCase {
/** Reset all breaker settings back to their defaults */
private void reset() {

View File

@ -92,7 +92,7 @@ import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
@ClusterScope(scope = Scope.SUITE, numDataNodes = 2, numClientNodes = 0, randomDynamicTemplates = false)
@ClusterScope(scope = Scope.SUITE, numDataNodes = 2, numClientNodes = 0)
@SuppressCodecs("*") // requires custom completion format
public class IndexStatsIT extends ESIntegTestCase {

View File

@ -52,7 +52,7 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
@ClusterScope(randomDynamicTemplates = false, scope = Scope.SUITE)
@ClusterScope(scope = Scope.SUITE)
public class SimpleValidateQueryIT extends ESIntegTestCase {
public void testSimpleValidateQuery() throws Exception {
createIndex("test");

View File

@ -410,11 +410,6 @@ public abstract class ESIntegTestCase extends ESTestCase {
randomSettingsBuilder.put("index.codec", CodecService.LUCENE_DEFAULT_CODEC);
}
XContentBuilder mappings = null;
if (frequently() && randomDynamicTemplates()) {
mappings = XContentFactory.jsonBuilder().startObject().startObject("_default_").endObject().endObject();
}
for (String setting : randomSettingsBuilder.internalMap().keySet()) {
assertThat("non index. prefix setting set on index template, its a node setting...", setting, startsWith("index."));
}
@ -435,10 +430,6 @@ public abstract class ESIntegTestCase extends ESTestCase {
.setPatterns(Collections.singletonList("*"))
.setOrder(0)
.setSettings(randomSettingsBuilder);
if (mappings != null) {
logger.info("test using _default_ mappings: [{}]", mappings.bytes().utf8ToString());
putTemplate.addMapping("_default_", mappings);
}
assertAcked(putTemplate.execute().actionGet());
}
}
@ -1591,11 +1582,6 @@ public abstract class ESIntegTestCase extends ESTestCase {
* ratio in the interval <code>[0..1]</code> is used.
*/
double transportClientRatio() default -1;
/**
* Return whether or not to enable dynamic templates for the mappings.
*/
boolean randomDynamicTemplates() default true;
}
private class LatchedActionListener<Response> implements ActionListener<Response> {
@ -1702,11 +1688,6 @@ public abstract class ESIntegTestCase extends ESTestCase {
return annotation == null ? InternalTestCluster.DEFAULT_NUM_CLIENT_NODES : annotation.numClientNodes();
}
private boolean randomDynamicTemplates() {
ClusterScope annotation = getAnnotation(this.getClass(), ClusterScope.class);
return annotation == null || annotation.randomDynamicTemplates();
}
/**
* This method is used to obtain settings for the <tt>Nth</tt> node in the cluster.
* Nodes in this cluster are associated with an ordinal number such that nodes can