Skip to content

Commit

Permalink
[Rest Api Compatibility] _time and _term sort orders (#74919)
Browse files Browse the repository at this point in the history
Previously removed in #39450, deprecated in es6 but not removed in es 7.
defaults to _key behaviour

relates #51816
  • Loading branch information
pgomulka committed Jul 6, 2021
1 parent 67fbc33 commit 72a58bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 0 additions & 2 deletions rest-api-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
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;
Expand Down Expand Up @@ -539,7 +541,7 @@ public static void writeHistogramOrder(BucketOrder order, StreamOutput out) thro
* 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}.
*
Expand Down Expand Up @@ -573,6 +575,13 @@ public static BucketOrder parseOrderParam(XContentParser parser) throws IOExcept
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;
Expand Down

0 comments on commit 72a58bc

Please sign in to comment.