Skip to content
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

Loosen the restrictions on disabling _all in 6.x #26259

Merged
merged 1 commit into from
Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down