From 9dc2c9b34bacbda42bb64f9ce872908fca08437a Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Thu, 17 Aug 2017 09:59:53 -0600 Subject: [PATCH] Loosen the restrictions on disabling _all in 6.x With 6.0+ we previously threw an exception when the `_all` field was configured at all. This loosens that restriction a little bit so that the error is only thrown when `_all` is enabled. A deprecation warning is returned/logged instead if any `_all` configuration is found. In 7.0, we retain the behavior of throwing an exception if `_all` is enabled at all. --- .../index/mapper/AllFieldMapper.java | 15 +++++++++++++-- .../index/mapper/MapperServiceTests.java | 7 ++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java index a13cbca17053d..79a2bbf6e601f 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java @@ -25,6 +25,8 @@ import org.apache.lucene.search.Query; import org.elasticsearch.Version; import org.elasticsearch.common.io.stream.BytesStreamOutput; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.lucene.all.AllEntries; import org.elasticsearch.common.lucene.all.AllField; import org.elasticsearch.common.lucene.all.AllTermQuery; @@ -45,6 +47,8 @@ public class AllFieldMapper extends MetadataFieldMapper { + private static final DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(AllFieldMapper.class)); + public static final String NAME = "_all"; public static final String CONTENT_TYPE = "_all"; @@ -105,8 +109,9 @@ public MetadataFieldMapper.Builder parse(String name, Map n ParserContext parserContext) throws MapperParsingException { if (node.isEmpty() == false && parserContext.indexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1)) { - throw new IllegalArgumentException("[_all] is disabled in 6.0. As a replacement, you can use an [copy_to] " + - "on mapping fields to create your own catch all field."); + deprecationLogger.deprecated("[_all] is deprecated in 6.0+ and will be removed in 7.0. " + + "As a replacement, you can use [copy_to] on " + + "mapping fields to create your own catch all field."); } Builder builder = new Builder(parserContext.mapperService().fullName(NAME)); builder.fieldType().setIndexAnalyzer(parserContext.getIndexAnalyzers().getDefaultIndexAnalyzer()); @@ -140,6 +145,12 @@ public MetadataFieldMapper.Builder parse(String name, Map n Object fieldNode = entry.getValue(); if (fieldName.equals("enabled")) { boolean enabled = TypeParsers.nodeBooleanValueLenient(name, "enabled", fieldNode); + if (enabled && node.isEmpty() == false && + parserContext.indexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1)) { + throw new IllegalArgumentException("Enabling [_all] is disabled in 6.0. " + + "As a replacement, you can use [copy_to] " + + "on mapping fields to create your own catch all field."); + } builder.enabled(enabled ? EnabledAttributeMapper.ENABLED : EnabledAttributeMapper.DISABLED); enabledSet = true; iterator.remove(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java b/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java index 6b79ee6e06fdf..240a1b2eb4686 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java @@ -254,15 +254,12 @@ public void testAllEnabled() throws Exception { .field("enabled", true) .endObject().endObject().bytes()); - CompressedXContent disabledAll = new CompressedXContent(XContentFactory.jsonBuilder().startObject() - .startObject("_all") - .field("enabled", false) - .endObject().endObject().bytes()); - Exception e = expectThrows(MapperParsingException.class, () -> indexService.mapperService().merge(MapperService.DEFAULT_MAPPING, enabledAll, MergeReason.MAPPING_UPDATE, random().nextBoolean())); assertThat(e.getMessage(), containsString("[_all] is disabled in 6.0")); + assertWarnings("[_all] is deprecated in 6.0+ and will be removed in 7.0. As a replacement, " + + "you can use [copy_to] on mapping fields to create your own catch all field."); } public void testPartitionedConstraints() {