Skip to content

Commit f6afabb

Browse files
committed
[Rest Api Compatibility] _time and _term sort orders
Previously removed in elastic#39450, deprecated in es6 but not removed in es 7. defaults to _key behaviour relates elastic#51816
1 parent 4ff3c89 commit f6afabb

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

rest-api-spec/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ tasks.named("yamlRestCompatTest").configure {
9797
'indices.upgrade/10_basic/Upgrade indices ignore unavailable',
9898
'mlt/20_docs/Basic mlt query with docs',
9999
'mlt/30_unlike/Basic mlt query with unlike',
100-
'search.aggregation/10_histogram/Deprecated _time order',
100+
// 'search.aggregation/10_histogram/Deprecated _time order',
101101
'search.aggregation/200_top_hits_metric/top_hits aggregation with sequence numbers',
102-
'search.aggregation/20_terms/Deprecated _term order',
102+
// 'search.aggregation/20_terms/Deprecated _term order',
103103
'search.aggregation/20_terms/*profiler*', // The profiler results aren't backwards compatible.
104104
'search.aggregation/51_filter_with_types/Filter aggs with terms lookup and ensure it\'s cached',
105105
'search.aggregation/370_doc_count_field/Test filters agg with doc_count', // Uses profiler for assertions which is not backwards compatible

server/src/main/java/org/elasticsearch/search/aggregations/InternalOrder.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
import org.elasticsearch.common.ParsingException;
1111
import org.elasticsearch.common.io.stream.StreamInput;
1212
import org.elasticsearch.common.io.stream.StreamOutput;
13+
import org.elasticsearch.common.logging.DeprecationLogger;
1314
import org.elasticsearch.common.util.Comparators;
1415
import org.elasticsearch.common.xcontent.XContent;
1516
import org.elasticsearch.common.xcontent.XContentBuilder;
1617
import org.elasticsearch.common.xcontent.XContentParser;
18+
import org.elasticsearch.core.RestApiVersion;
1719
import org.elasticsearch.search.aggregations.Aggregator.BucketComparator;
1820
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket;
1921
import org.elasticsearch.search.aggregations.support.AggregationPath;
@@ -539,7 +541,7 @@ public static void writeHistogramOrder(BucketOrder order, StreamOutput out) thro
539541
* Contains logic for parsing a {@link BucketOrder} from a {@link XContentParser}.
540542
*/
541543
public static class Parser {
542-
544+
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(Parser.class);
543545
/**
544546
* Parse a {@link BucketOrder} from {@link XContent}.
545547
*
@@ -573,6 +575,13 @@ public static BucketOrder parseOrderParam(XContentParser parser) throws IOExcept
573575
throw new ParsingException(parser.getTokenLocation(),
574576
"Must specify at least one field for [order]");
575577
}
578+
// _term and _time order deprecated in 6.0; replaced by _key
579+
if (parser.getRestApiVersion() == RestApiVersion.V_7 &&
580+
("_term".equals(orderKey) || "_time".equals(orderKey))) {
581+
deprecationLogger.compatibleApiWarning("_term_and_time_key_removal" ,
582+
"Deprecated aggregation order key [{}] used, replaced by [_key]", orderKey);
583+
return orderAsc ? KEY_ASC : KEY_DESC;
584+
}
576585
switch (orderKey) {
577586
case "_key":
578587
return orderAsc ? KEY_ASC : KEY_DESC;

0 commit comments

Comments
 (0)