From ff8aede63a66590c217c0a2236299d12878da433 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Mon, 12 Jul 2021 12:08:45 +0200 Subject: [PATCH] [Rest Api Compatibility] MoreLikeThisQuery with types (#75123) previously removed in #42198 also adding a type for MultiTermVectorsResponse in failures relates #54160 relates #51816 --- rest-api-spec/build.gradle | 6 ------ .../termvectors/MultiTermVectorsResponse.java | 5 +++++ .../action/termvectors/TermVectorsResponse.java | 1 - .../index/query/MoreLikeThisQueryBuilder.java | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/rest-api-spec/build.gradle b/rest-api-spec/build.gradle index 33745fa705bd0..81a8bc75d997b 100644 --- a/rest-api-spec/build.gradle +++ b/rest-api-spec/build.gradle @@ -91,17 +91,11 @@ tasks.named("yamlRestCompatTest").configure { 'indices.open/10_basic/?wait_for_active_shards=index-setting', // not fixing this in #70966 'indices.put_template/11_basic_with_types/Put template with empty mappings', - 'mlt/20_docs/Basic mlt query with docs', - 'mlt/30_unlike/Basic mlt query with unlike', 'search.aggregation/200_top_hits_metric/top_hits aggregation with sequence numbers', 'search.aggregation/20_terms/*profiler*', // The profiler results aren't backwards compatible. 'search.aggregation/51_filter_with_types/Filter aggs with terms lookup and ensure it\'s cached', 'search.aggregation/370_doc_count_field/Test filters agg with doc_count', // Uses profiler for assertions which is not backwards compatible - 'mtermvectors/11_basic_with_types/Basic tests for multi termvector get', - 'mtermvectors/21_deprecated_with_types/Deprecated camel case and _ parameters should fail in Term Vectors query', - 'mtermvectors/30_mix_typeless_typeful/mtermvectors without types on an index that has types', 'search/150_rewrite_on_coordinator/Ensure that we fetch the document only once', //terms_lookup - 'search/171_terms_query_with_types/Terms Query with No.of terms exceeding index.max_terms_count should FAIL', //bulk 'search/260_parameter_validation/test size=-1 is deprecated', //size=-1 change 'search/310_match_bool_prefix/multi_match multiple fields with cutoff_frequency throws exception', //cutoff_frequency 'search/340_type_query/type query', // type_query - probably should behave like match_all diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java index 6d26501106262..ffe2c82c070cc 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/MultiTermVectorsResponse.java @@ -16,6 +16,8 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.core.RestApiVersion; +import org.elasticsearch.index.mapper.MapperService; import java.io.IOException; import java.util.Arrays; @@ -112,6 +114,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.startObject(); Failure failure = response.getFailure(); builder.field(Fields._INDEX, failure.getIndex()); + if (builder.getRestApiVersion() == RestApiVersion.V_7) { + builder.field(Fields._TYPE, MapperService.SINGLE_MAPPING_NAME); + } builder.field(Fields._ID, failure.getId()); ElasticsearchException.generateFailureXContent(builder, params, failure.getCause(), true); builder.endObject(); diff --git a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsResponse.java b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsResponse.java index 0a4456ab07951..da817fa334ebb 100644 --- a/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/termvectors/TermVectorsResponse.java @@ -57,7 +57,6 @@ private static class FieldStrings { public static final String END_OFFSET = "end_offset"; public static final String PAYLOAD = "payload"; public static final String _INDEX = "_index"; - public static final String _TYPE = "_type"; public static final String _ID = "_id"; public static final String _VERSION = "_version"; public static final String FOUND = "found"; diff --git a/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java index 496e06891c687..5b6e12d09b8fd 100644 --- a/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java @@ -23,6 +23,7 @@ import org.elasticsearch.action.termvectors.TermVectorsRequest; import org.elasticsearch.action.termvectors.TermVectorsResponse; import org.elasticsearch.client.Client; +import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.core.Nullable; import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.common.ParsingException; @@ -40,10 +41,12 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.core.RestApiVersion; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.mapper.IdFieldMapper; import org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType; import org.elasticsearch.index.mapper.MappedFieldType; +import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.TextFieldMapper.TextFieldType; import java.io.IOException; @@ -67,6 +70,10 @@ */ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder { public static final String NAME = "more_like_this"; + private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(MoreLikeThisQueryBuilder.class); + static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Types are deprecated in [more_like_this] " + + "queries. The type should no longer be specified in the [like] and [unlike] sections."; + public static final int DEFAULT_MAX_QUERY_TERMS = XMoreLikeThis.DEFAULT_MAX_QUERY_TERMS; public static final int DEFAULT_MIN_TERM_FREQ = XMoreLikeThis.DEFAULT_MIN_TERM_FREQ; @@ -99,6 +106,7 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder