Skip to content

Commit dd7d37c

Browse files
authored
[Rest Api Compatibility] Ignore use_field_mapping option for docvalue (#74435)
previously removed in #55622 use_field_mapping option can be used on doc value format under rest api compatibility. The value itself is ignored (replaced with null) as it is a default behaviour to use field mapping format. relates #51816
1 parent d6b3706 commit dd7d37c

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

rest-api-spec/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ tasks.named("yamlRestCompatTest").configure {
104104
'mtermvectors/11_basic_with_types/Basic tests for multi termvector get',
105105
'mtermvectors/21_deprecated_with_types/Deprecated camel case and _ parameters should fail in Term Vectors query',
106106
'mtermvectors/30_mix_typeless_typeful/mtermvectors without types on an index that has types',
107-
'search/10_source_filtering/docvalue_fields with default format', //use_field_mapping change
108107
'search/150_rewrite_on_coordinator/Ensure that we fetch the document only once', //terms_lookup
109108
'search/171_terms_query_with_types/Terms Query with No.of terms exceeding index.max_terms_count should FAIL', //bulk
110109
'search/260_parameter_validation/test size=-1 is deprecated', //size=-1 change

server/src/main/java/org/elasticsearch/search/fetch/subphase/FieldAndFormat.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,35 @@
99
package org.elasticsearch.search.fetch.subphase;
1010

1111
import org.elasticsearch.Version;
12-
import org.elasticsearch.core.Nullable;
13-
import org.elasticsearch.common.xcontent.ParseField;
1412
import org.elasticsearch.common.io.stream.StreamInput;
1513
import org.elasticsearch.common.io.stream.StreamOutput;
1614
import org.elasticsearch.common.io.stream.Writeable;
15+
import org.elasticsearch.common.logging.DeprecationLogger;
1716
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
17+
import org.elasticsearch.common.xcontent.ObjectParser;
18+
import org.elasticsearch.common.xcontent.ParseField;
1819
import org.elasticsearch.common.xcontent.ToXContentObject;
1920
import org.elasticsearch.common.xcontent.XContent;
2021
import org.elasticsearch.common.xcontent.XContentBuilder;
2122
import org.elasticsearch.common.xcontent.XContentParser;
23+
import org.elasticsearch.core.CheckedFunction;
24+
import org.elasticsearch.core.Nullable;
25+
import org.elasticsearch.core.RestApiVersion;
2226

2327
import java.io.IOException;
2428
import java.util.Objects;
2529

30+
import static org.elasticsearch.core.RestApiVersion.equalTo;
31+
import static org.elasticsearch.core.RestApiVersion.onOrAfter;
32+
2633
/**
2734
* Wrapper around a field name and the format that should be used to
2835
* display values of this field.
2936
*/
3037
public final class FieldAndFormat implements Writeable, ToXContentObject {
38+
private static final String USE_DEFAULT_FORMAT = "use_field_mapping";
39+
private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(FetchDocValuesPhase.class);
40+
3141
private static final ParseField FIELD_FIELD = new ParseField("field");
3242
private static final ParseField FORMAT_FIELD = new ParseField("format");
3343
private static final ParseField INCLUDE_UNMAPPED_FIELD = new ParseField("include_unmapped");
@@ -38,10 +48,33 @@ public final class FieldAndFormat implements Writeable, ToXContentObject {
3848

3949
static {
4050
PARSER.declareString(ConstructingObjectParser.constructorArg(), FIELD_FIELD);
41-
PARSER.declareStringOrNull(ConstructingObjectParser.optionalConstructorArg(), FORMAT_FIELD);
51+
PARSER.declareStringOrNull(ConstructingObjectParser.optionalConstructorArg(),
52+
FORMAT_FIELD.forRestApiVersion(onOrAfter(RestApiVersion.V_8)));
53+
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(),
54+
ignoreUseFieldMappingStringParser(),
55+
FORMAT_FIELD.forRestApiVersion(equalTo(RestApiVersion.V_7)),
56+
ObjectParser.ValueType.STRING_OR_NULL);
4257
PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), INCLUDE_UNMAPPED_FIELD);
4358
}
4459

60+
private static CheckedFunction<XContentParser, String, IOException> ignoreUseFieldMappingStringParser() {
61+
return (p) -> {
62+
if (p.currentToken() == XContentParser.Token.VALUE_NULL) {
63+
return null;
64+
} else {
65+
String text = p.text();
66+
if (text.equals(USE_DEFAULT_FORMAT)) {
67+
DEPRECATION_LOGGER.compatibleApiWarning("explicit_default_format",
68+
"[" + USE_DEFAULT_FORMAT + "] is a special format that was only used to " +
69+
"ease the transition to 7.x. It has become the default and shouldn't be set explicitly anymore.");
70+
return null;
71+
} else {
72+
return text;
73+
}
74+
}
75+
};
76+
}
77+
4578
/**
4679
* Parse a {@link FieldAndFormat} from some {@link XContent}.
4780
*/

0 commit comments

Comments
 (0)