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

Emit deprecation warnings when boosts are defined in mappings #62623

Merged
merged 4 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -570,6 +570,9 @@ public final void parse(String name, ParserContext parserContext, Map<String, Ob
throw new MapperParsingException("unknown parameter [" + propName
+ "] on mapper [" + name + "] of type [" + type + "]");
}
if (Objects.equals("boost", propName)) {
deprecationLogger.deprecate("boost", "Parameter [boost] on field [{}] is deprecated", name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add that it will be removed in 8 since that's the new plan ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

}
if (propNode == null && parameter.acceptsNull == false) {
throw new MapperParsingException("[" + propName + "] on mapper [" + name
+ "] of type [" + type + "] must not have a [null] value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public static void parseField(FieldMapper.Builder<?> builder, String name, Map<S
iterator.remove();
} else if (propName.equals("boost")) {
builder.boost(nodeFloatValue(propNode));
deprecationLogger.deprecate("boost", "Parameter [boost] on field [{}] is deprecated", name);
iterator.remove();
} else if (propName.equals("index_options")) {
builder.indexOptions(nodeIndexOptionValue(propNode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ protected void minimalMapping(XContentBuilder b) throws IOException {
b.field("type", "boolean");
}

@Override
protected void assertParseMaximalWarnings() {
assertWarnings("Parameter [boost] on field [field] is deprecated");
}

public void testDefaults() throws IOException {

MapperService mapperService = createMapperService(fieldMapping(this::minimalMapping));
Expand Down Expand Up @@ -170,6 +175,7 @@ public void testBoosts() throws Exception {

MappedFieldType ft = mapperService.fieldType("field");
assertEquals(new BoostQuery(new TermQuery(new Term("field", "T")), 2.0f), ft.termQuery("true", null));
assertParseMaximalWarnings();
}

public void testFetchSourceValue() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ protected void minimalMapping(XContentBuilder b) throws IOException {
b.field("type", "date");
}

@Override
protected void assertParseMaximalWarnings() {
assertWarnings("Parameter [boost] on field [field] is deprecated");
}

public void testDefaults() throws Exception {
DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping));
ParsedDocument doc = mapper.parse(source(b -> b.field("field", "2016-03-11")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ protected void minimalMapping(XContentBuilder b) throws IOException {
b.field("type", "keyword");
}

@Override
protected void assertParseMaximalWarnings() {
assertWarnings("Parameter [boost] on field [field] is deprecated");
}

public void testDefaults() throws Exception {
XContentBuilder mapping = fieldMapping(this::minimalMapping);
DocumentMapper mapper = createDocumentMapper(mapping);
Expand Down Expand Up @@ -235,6 +240,7 @@ public void testIndexOptions() throws IOException {
public void testBoost() throws IOException {
MapperService mapperService = createMapperService(fieldMapping(b -> b.field("type", "keyword").field("boost", 2f)));
assertThat(mapperService.fieldType("field").boost(), equalTo(2f));
assertWarnings("Parameter [boost] on field [field] is deprecated");
}

public void testEnableNorms() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ protected void minimalMapping(XContentBuilder b) throws IOException {
b.field("type", "long_range");
}

@Override
protected void assertParseMaximalWarnings() {
assertWarnings("Parameter [boost] on field [field] is deprecated");
}

private Object getFrom(String type) {
if (type.equals("date_range")) {
return FROM_DATE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public void testExceptionUsingAnalyzerOnNumericField() {
@Override
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
mapperService.merge("_doc", new CompressedXContent(Strings.toString(PutMappingRequest.simpleMapping(
"string_boost", "type=text,boost=4", "string_no_pos",
"string_boost", "type=text", "string_no_pos",
"type=text,index_options=docs"))
),
MapperService.MergeReason.MAPPING_UPDATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.function.BiFunction;
import java.util.function.Supplier;

import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -82,13 +83,17 @@ public void testMinimalToMaximal() throws IOException {
createMapperService(orig).documentMapper().mapping().toXContent(parsedFromOrig, INCLUDE_DEFAULTS);
parsedFromOrig.endObject();
assertEquals(Strings.toString(orig), Strings.toString(parsedFromOrig));
assertParseMinimalWarnings();
assertParseMaximalWarnings();
}

protected void assertParseMinimalWarnings() {
// Most mappers don't emit any warnings
}

protected void assertParseMaximalWarnings() {
// Most mappers don't emit any warnings
}

/**
* Override to disable testing {@code meta} in fields that don't support it.
*/
Expand Down Expand Up @@ -132,6 +137,22 @@ public final void testMeta() throws IOException {
);
}

public final void testDeprecatedBoost() throws IOException {
try {
createMapperService(fieldMapping(b -> {
minimalMapping(b);
b.field("boost", 2.0);
}));
assertWarnings("Parameter [boost] on field [field] is deprecated");
}
catch (MapperParsingException e) {
assertThat(e.getMessage(), anyOf(
containsString("unknown parameter [boost]"),
containsString("[boost : 2.0]")));
}
assertParseMinimalWarnings();
}

public static List<?> fetchSourceValue(FieldMapper mapper, Object sourceValue) throws IOException {
return fetchSourceValue(mapper, sourceValue, null);
}
Expand Down