|
@@ -18,6 +18,8 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.util.Maps;
|
|
|
import org.elasticsearch.common.util.set.Sets;
|
|
|
+import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
|
|
+import org.elasticsearch.core.RestApiVersion;
|
|
|
import org.elasticsearch.index.Index;
|
|
|
import org.elasticsearch.index.IndexSettings;
|
|
|
import org.elasticsearch.index.IndexVersion;
|
|
@@ -46,6 +48,7 @@ import org.elasticsearch.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.xcontent.XContentFactory;
|
|
|
import org.elasticsearch.xcontent.XContentParseException;
|
|
|
import org.elasticsearch.xcontent.XContentParser;
|
|
|
+import org.elasticsearch.xcontent.XContentParserConfiguration;
|
|
|
import org.elasticsearch.xcontent.XContentType;
|
|
|
import org.elasticsearch.xcontent.json.JsonXContent;
|
|
|
import org.junit.AfterClass;
|
|
@@ -607,6 +610,36 @@ public class HighlightBuilderTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testForceSourceRemovedInV9() throws IOException {
|
|
|
+ String highlightJson = """
|
|
|
+ { "fields" : { }, "force_source" : true }
|
|
|
+ """;
|
|
|
+
|
|
|
+ XContentParserConfiguration config = XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry())
|
|
|
+ .withDeprecationHandler(LoggingDeprecationHandler.INSTANCE)
|
|
|
+ .withRestApiVersion(RestApiVersion.V_9);
|
|
|
+ try (XContentParser parser = JsonXContent.jsonXContent.createParser(config, highlightJson)) {
|
|
|
+ XContentParseException xContentParseException = expectThrows(
|
|
|
+ XContentParseException.class,
|
|
|
+ () -> HighlightBuilder.fromXContent(parser)
|
|
|
+ );
|
|
|
+ assertThat(xContentParseException.getMessage(), containsString("unknown field [force_source]"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testForceSourceV8Comp() throws IOException {
|
|
|
+ String highlightJson = """
|
|
|
+ { "fields" : { }, "force_source" : true }
|
|
|
+ """;
|
|
|
+ XContentParserConfiguration config = XContentParserConfiguration.EMPTY.withRegistry(xContentRegistry())
|
|
|
+ .withDeprecationHandler(LoggingDeprecationHandler.INSTANCE)
|
|
|
+ .withRestApiVersion(RestApiVersion.V_8);
|
|
|
+ try (XContentParser parser = JsonXContent.jsonXContent.createParser(config, highlightJson)) {
|
|
|
+ HighlightBuilder.fromXContent(parser);
|
|
|
+ assertWarnings("Deprecated field [force_source] used, this field is unused and will be removed entirely");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
protected static XContentBuilder toXContent(HighlightBuilder highlight, XContentType contentType) throws IOException {
|
|
|
XContentBuilder builder = XContentFactory.contentBuilder(contentType);
|
|
|
if (randomBoolean()) {
|