-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Rest Api Compatibility] Ignore use_field_mapping option for docvalue #74435
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
Changes from all commits
019291a
32698c3
837acb0
44e4148
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,25 +9,35 @@ | |
| package org.elasticsearch.search.fetch.subphase; | ||
|
|
||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.core.Nullable; | ||
| import org.elasticsearch.common.xcontent.ParseField; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
| import org.elasticsearch.common.logging.DeprecationLogger; | ||
| import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
| import org.elasticsearch.common.xcontent.ObjectParser; | ||
| import org.elasticsearch.common.xcontent.ParseField; | ||
| import org.elasticsearch.common.xcontent.ToXContentObject; | ||
| import org.elasticsearch.common.xcontent.XContent; | ||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.core.CheckedFunction; | ||
| import org.elasticsearch.core.Nullable; | ||
| import org.elasticsearch.core.RestApiVersion; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Objects; | ||
|
|
||
| import static org.elasticsearch.core.RestApiVersion.equalTo; | ||
| import static org.elasticsearch.core.RestApiVersion.onOrAfter; | ||
|
|
||
| /** | ||
| * Wrapper around a field name and the format that should be used to | ||
| * display values of this field. | ||
| */ | ||
| public final class FieldAndFormat implements Writeable, ToXContentObject { | ||
| private static final String USE_DEFAULT_FORMAT = "use_field_mapping"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class is also used by the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, I was not aware of this.. I don't think the parser has the information about the parent of the current key/value..
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also feel like this is the right trade-off to keep the code simple. |
||
| private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(FetchDocValuesPhase.class); | ||
|
|
||
| private static final ParseField FIELD_FIELD = new ParseField("field"); | ||
| private static final ParseField FORMAT_FIELD = new ParseField("format"); | ||
| private static final ParseField INCLUDE_UNMAPPED_FIELD = new ParseField("include_unmapped"); | ||
|
|
@@ -38,10 +48,33 @@ public final class FieldAndFormat implements Writeable, ToXContentObject { | |
|
|
||
| static { | ||
| PARSER.declareString(ConstructingObjectParser.constructorArg(), FIELD_FIELD); | ||
| PARSER.declareStringOrNull(ConstructingObjectParser.optionalConstructorArg(), FORMAT_FIELD); | ||
| PARSER.declareStringOrNull(ConstructingObjectParser.optionalConstructorArg(), | ||
| FORMAT_FIELD.forRestApiVersion(onOrAfter(RestApiVersion.V_8))); | ||
| PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(), | ||
| ignoreUseFieldMappingStringParser(), | ||
| FORMAT_FIELD.forRestApiVersion(equalTo(RestApiVersion.V_7)), | ||
| ObjectParser.ValueType.STRING_OR_NULL); | ||
| PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), INCLUDE_UNMAPPED_FIELD); | ||
| } | ||
|
|
||
| private static CheckedFunction<XContentParser, String, IOException> ignoreUseFieldMappingStringParser() { | ||
| return (p) -> { | ||
| if (p.currentToken() == XContentParser.Token.VALUE_NULL) { | ||
| return null; | ||
| } else { | ||
| String text = p.text(); | ||
| if (text.equals(USE_DEFAULT_FORMAT)) { | ||
| DEPRECATION_LOGGER.compatibleApiWarning("explicit_default_format", | ||
| "[" + USE_DEFAULT_FORMAT + "] is a special format that was only used to " + | ||
| "ease the transition to 7.x. It has become the default and shouldn't be set explicitly anymore."); | ||
| return null; | ||
| } else { | ||
| return text; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Parse a {@link FieldAndFormat} from some {@link XContent}. | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the 7.x test asserts about the deprecation warning and the right format (declared on mapping) being used