-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Restore a noop _all metadata field for 6x indices #37808
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4815fe7
Add failing rolling upgrade test
dakrone 4fd240f
Merge branch 'master' into all_field_bug
jimczi c949fbf
Restore a noop _all metadata field for 6x indices
jimczi 88b5f9b
fix mapper serialization when not explicitly disabled
jimczi cdaa804
address review
jimczi a0b6e65
Merge branch 'master' into all_field_bug
jimczi eba12c5
Merge branch 'master' into all_field_bug
jimczi e6519f4
remove _all from exists query tests
jimczi 1e72b4d
fix checkstyle
jimczi 3697eea
Merge branch 'master' into all_field_bug
jimczi 6e7a0d4
Merge branch 'master' into all_field_bug
jimczi 7d9b4a1
fix test bug
jimczi 1dd9765
line len
jimczi e66c59c
Merge branch 'master' into all_field_bug
jimczi 84ccd8f
Merge branch 'master' into all_field_bug
jimczi 47d9846
Merge branch 'master' into all_field_bug
jimczi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
server/src/main/java/org/elasticsearch/index/mapper/AllFieldMapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.index.mapper; | ||
|
||
import org.apache.lucene.index.IndexOptions; | ||
import org.apache.lucene.index.IndexableField; | ||
import org.apache.lucene.search.MatchNoDocsQuery; | ||
import org.apache.lucene.search.Query; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.support.XContentMapValues; | ||
import org.elasticsearch.index.query.QueryShardContext; | ||
|
||
import java.io.IOException; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Noop mapper that ensures that mappings created in 6x that explicitly disable the _all field | ||
* can be restored in this version. | ||
* | ||
* TODO: Remove in 8 | ||
*/ | ||
public class AllFieldMapper extends MetadataFieldMapper { | ||
public static final String NAME = "_all"; | ||
public static final String CONTENT_TYPE = "_all"; | ||
|
||
public static class Defaults { | ||
public static final MappedFieldType FIELD_TYPE = new AllFieldType(); | ||
|
||
static { | ||
FIELD_TYPE.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); | ||
FIELD_TYPE.setTokenized(true); | ||
FIELD_TYPE.setName(NAME); | ||
FIELD_TYPE.freeze(); | ||
} | ||
} | ||
|
||
public static class Builder extends MetadataFieldMapper.Builder<Builder, AllFieldMapper> { | ||
private boolean disableExplicit = false; | ||
|
||
public Builder(MappedFieldType existing) { | ||
super(NAME, existing == null ? Defaults.FIELD_TYPE : existing, Defaults.FIELD_TYPE); | ||
builder = this; | ||
} | ||
|
||
private Builder setDisableExplicit() { | ||
this.disableExplicit = true; | ||
return this; | ||
} | ||
|
||
@Override | ||
public AllFieldMapper build(BuilderContext context) { | ||
return new AllFieldMapper(fieldType, context.indexSettings(), disableExplicit); | ||
} | ||
} | ||
|
||
public static class TypeParser implements MetadataFieldMapper.TypeParser { | ||
@Override | ||
public MetadataFieldMapper.Builder<?,?> parse(String name, Map<String, Object> node, | ||
ParserContext parserContext) throws MapperParsingException { | ||
Builder builder = new Builder(parserContext.mapperService().fullName(NAME)); | ||
for (Iterator<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) { | ||
Map.Entry<String, Object> entry = iterator.next(); | ||
String fieldName = entry.getKey(); | ||
if (fieldName.equals("enabled")) { | ||
boolean enabled = XContentMapValues.nodeBooleanValue(entry.getValue(), "enabled"); | ||
if (enabled) { | ||
throw new IllegalArgumentException("[_all] is disabled in this version."); | ||
} | ||
builder.setDisableExplicit(); | ||
iterator.remove(); | ||
} | ||
} | ||
return builder; | ||
} | ||
|
||
@Override | ||
public MetadataFieldMapper getDefault(MappedFieldType fieldType, ParserContext context) { | ||
final Settings indexSettings = context.mapperService().getIndexSettings().getSettings(); | ||
return new AllFieldMapper(indexSettings, Defaults.FIELD_TYPE, false); | ||
} | ||
} | ||
|
||
static final class AllFieldType extends StringFieldType { | ||
AllFieldType() { | ||
} | ||
|
||
protected AllFieldType(AllFieldType ref) { | ||
super(ref); | ||
} | ||
|
||
@Override | ||
public MappedFieldType clone() { | ||
return new AllFieldType(this); | ||
} | ||
|
||
@Override | ||
public String typeName() { | ||
return CONTENT_TYPE; | ||
} | ||
|
||
@Override | ||
public Query existsQuery(QueryShardContext context) { | ||
return new MatchNoDocsQuery(); | ||
} | ||
} | ||
|
||
private final boolean disableExplicit; | ||
|
||
private AllFieldMapper(Settings indexSettings, MappedFieldType existing, boolean disableExplicit) { | ||
this(existing.clone(), indexSettings, disableExplicit); | ||
} | ||
|
||
private AllFieldMapper(MappedFieldType fieldType, Settings indexSettings, boolean disableExplicit) { | ||
super(NAME, fieldType, Defaults.FIELD_TYPE, indexSettings); | ||
this.disableExplicit = disableExplicit; | ||
} | ||
|
||
@Override | ||
public void preParse(ParseContext context) throws IOException { | ||
} | ||
|
||
@Override | ||
public void postParse(ParseContext context) throws IOException { | ||
super.parse(context); | ||
} | ||
|
||
@Override | ||
public void parse(ParseContext context) throws IOException { | ||
// we parse in post parse | ||
} | ||
|
||
@Override | ||
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException { | ||
// noop mapper | ||
return; | ||
} | ||
|
||
@Override | ||
protected String contentType() { | ||
return CONTENT_TYPE; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
boolean includeDefaults = params.paramAsBoolean("include_defaults", false); | ||
if (includeDefaults || disableExplicit) { | ||
builder.startObject(CONTENT_TYPE); | ||
if (disableExplicit) { | ||
builder.field("enabled", false); | ||
} | ||
builder.endObject(); | ||
} | ||
return builder; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.