Skip to content

Commit

Permalink
Deprecates the ability to sort terms aggregation by ascending count
Browse files Browse the repository at this point in the history
Relates to #17614
  • Loading branch information
jimczi committed Jun 17, 2016
1 parent d895636 commit a942b8d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.elasticsearch.search.aggregations.bucket.terms;

import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.aggregations.Aggregator;
import org.elasticsearch.search.aggregations.AggregatorFactory;
Expand All @@ -36,6 +38,8 @@
*
*/
public class TermsParser implements Aggregator.Parser {
private static final DeprecationLogger DEPRECATION_LOGGER =
new DeprecationLogger(Loggers.getLogger(TermsParser.class));

@Override
public String type() {
Expand All @@ -52,6 +56,10 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se
List<OrderElement> orderElements = aggParser.getOrderElements();
List<Terms.Order> orders = new ArrayList<>(orderElements.size());
for (OrderElement orderElement : orderElements) {
Terms.Order order = resolveOrder(orderElement.key(), orderElement.asc());
if (InternalOrder.isCountDesc(order)) {
DEPRECATION_LOGGER.deprecated("sorting by ascending count is deprecated and will be removed in the next major version");
}
orders.add(resolveOrder(orderElement.key(), orderElement.asc()));
}
Terms.Order order;
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/migration/migrate_2_0/aggs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ which applies to all bucket aggregations:
except the `filters` and `terms` aggregations.


==== `order: {"count": "asc"}` on Terms
The ability to sort the terms aggregation by ascending count has been deprecated.
It is not recommended as it can return inaccurate doc counts and/or select the wrong buckets.

0 comments on commit a942b8d

Please sign in to comment.