Selaa lähdekoodia

[Rest Api Compatibility] _time and _term sort orders (#74919)

Previously removed in #39450, deprecated in es6 but not removed in es 7.
defaults to _key behaviour

relates #51816
Przemyslaw Gomulka 4 vuotta sitten
vanhempi
commit
72a58bc338

+ 0 - 2
rest-api-spec/build.gradle

@@ -97,9 +97,7 @@ tasks.named("yamlRestCompatTest").configure {
     'indices.upgrade/10_basic/Upgrade indices ignore unavailable',
     'mlt/20_docs/Basic mlt query with docs',
     'mlt/30_unlike/Basic mlt query with unlike',
-    'search.aggregation/10_histogram/Deprecated _time order',
     'search.aggregation/200_top_hits_metric/top_hits aggregation with sequence numbers',
-    'search.aggregation/20_terms/Deprecated _term order',
     '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

+ 10 - 1
server/src/main/java/org/elasticsearch/search/aggregations/InternalOrder.java

@@ -10,10 +10,12 @@ package org.elasticsearch.search.aggregations;
 import org.elasticsearch.common.ParsingException;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
+import org.elasticsearch.common.logging.DeprecationLogger;
 import org.elasticsearch.common.util.Comparators;
 import org.elasticsearch.common.xcontent.XContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.core.RestApiVersion;
 import org.elasticsearch.search.aggregations.Aggregator.BucketComparator;
 import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
 import org.elasticsearch.search.aggregations.support.AggregationPath;
@@ -539,7 +541,7 @@ public abstract class InternalOrder extends BucketOrder {
      * Contains logic for parsing a {@link BucketOrder} from a {@link XContentParser}.
      */
     public static class Parser {
-
+        private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(Parser.class);
         /**
          * Parse a {@link BucketOrder} from {@link XContent}.
          *
@@ -573,6 +575,13 @@ public abstract class InternalOrder extends BucketOrder {
                 throw new ParsingException(parser.getTokenLocation(),
                     "Must specify at least one field for [order]");
             }
+            // _term and _time order deprecated in 6.0; replaced by _key
+            if (parser.getRestApiVersion() == RestApiVersion.V_7 &&
+                ("_term".equals(orderKey) || "_time".equals(orderKey))) {
+                deprecationLogger.compatibleApiWarning("_term_and_time_key_removal" ,
+                    "Deprecated aggregation order key [{}] used, replaced by [_key]", orderKey);
+                return orderAsc ? KEY_ASC : KEY_DESC;
+            }
             switch (orderKey) {
                 case "_key":
                     return orderAsc ? KEY_ASC : KEY_DESC;