Skip to content

Commit

Permalink
Loosen the restrictions on disabling _all in 6.x (#26259)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dakrone committed Aug 17, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 99b91df commit a50fe31
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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<String, Object> 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();
Original file line number Diff line number Diff line change
@@ -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() {

0 comments on commit a50fe31

Please sign in to comment.