|
18 | 18 | import org.elasticsearch.common.settings.Settings; |
19 | 19 | import org.elasticsearch.common.util.Maps; |
20 | 20 | import org.elasticsearch.common.util.set.Sets; |
| 21 | +import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; |
| 22 | +import org.elasticsearch.core.RestApiVersion; |
21 | 23 | import org.elasticsearch.index.Index; |
22 | 24 | import org.elasticsearch.index.IndexSettings; |
23 | 25 | import org.elasticsearch.index.IndexVersion; |
|
46 | 48 | import org.elasticsearch.xcontent.XContentFactory; |
47 | 49 | import org.elasticsearch.xcontent.XContentParseException; |
48 | 50 | import org.elasticsearch.xcontent.XContentParser; |
| 51 | +import org.elasticsearch.xcontent.XContentParserConfiguration; |
49 | 52 | import org.elasticsearch.xcontent.XContentType; |
50 | 53 | import org.elasticsearch.xcontent.json.JsonXContent; |
51 | 54 | import org.junit.AfterClass; |
@@ -607,6 +610,36 @@ public void testOrderSerialization() throws Exception { |
607 | 610 | } |
608 | 611 | } |
609 | 612 |
|
| 613 | + public void testForceSourceRemovedInV9() throws IOException { |
| 614 | + String highlightJson = """ |
| 615 | + { "fields" : { }, "force_source" : true } |
| 616 | + """; |
| 617 | + |
| 618 | + XContentParserConfiguration config = XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry()) |
| 619 | + .withDeprecationHandler(LoggingDeprecationHandler.INSTANCE) |
| 620 | + .withRestApiVersion(RestApiVersion.V_9); |
| 621 | + try (XContentParser parser = JsonXContent.jsonXContent.createParser(config, highlightJson)) { |
| 622 | + XContentParseException xContentParseException = expectThrows( |
| 623 | + XContentParseException.class, |
| 624 | + () -> HighlightBuilder.fromXContent(parser) |
| 625 | + ); |
| 626 | + assertThat(xContentParseException.getMessage(), containsString("unknown field [force_source]")); |
| 627 | + } |
| 628 | + } |
| 629 | + |
| 630 | + public void testForceSourceV8Comp() throws IOException { |
| 631 | + String highlightJson = """ |
| 632 | + { "fields" : { }, "force_source" : true } |
| 633 | + """; |
| 634 | + XContentParserConfiguration config = XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry()) |
| 635 | + .withDeprecationHandler(LoggingDeprecationHandler.INSTANCE) |
| 636 | + .withRestApiVersion(RestApiVersion.V_8); |
| 637 | + try (XContentParser parser = JsonXContent.jsonXContent.createParser(config, highlightJson)) { |
| 638 | + HighlightBuilder.fromXContent(parser); |
| 639 | + assertWarnings("Deprecated field [force_source] used, this field is unused and will be removed entirely"); |
| 640 | + } |
| 641 | + } |
| 642 | + |
610 | 643 | protected static XContentBuilder toXContent(HighlightBuilder highlight, XContentType contentType) throws IOException { |
611 | 644 | XContentBuilder builder = XContentFactory.contentBuilder(contentType); |
612 | 645 | if (randomBoolean()) { |
|
0 commit comments