-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Terms Method to Support Ascending and Descending Ordering #3540
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,11 +263,19 @@ public SearchResult search(SearchesConfig config) { | |
return new SearchResult(r.getHits(), indices, config.query(), request.source(), r.getTook()); | ||
} | ||
|
||
public TermsResult terms(String field, int size, String query, String filter, TimeRange range) { | ||
public TermsResult terms(String field, int size, String query, String filter, TimeRange range, String sorting) { | ||
Terms.Order termsOrder; | ||
|
||
if (size == 0) { | ||
size = 50; | ||
} | ||
|
||
if (sorting.equals("descending")){ | ||
termsOrder = Terms.Order.count(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @joschi. I am using count because I am ordering based on the returned document count of the aggregation instead of the term itself. Per the docs: https://www.elastic.co/guide/en/elasticsearch/client/java-api/2.4/_bucket_aggregations.html#_order
|
||
} else { | ||
termsOrder = Terms.Order.count(true); | ||
} | ||
|
||
SearchRequestBuilder srb; | ||
if (filter == null) { | ||
srb = standardSearchRequest(query, determineAffectedIndices(range, null), range); | ||
|
@@ -279,7 +287,8 @@ public TermsResult terms(String field, int size, String query, String filter, Ti | |
.subAggregation( | ||
AggregationBuilders.terms(AGG_TERMS) | ||
.field(field) | ||
.size(size)) | ||
.size(size) | ||
.order(termsOrder)) | ||
.subAggregation( | ||
AggregationBuilders.missing("missing") | ||
.field(field)) | ||
|
@@ -302,8 +311,12 @@ public TermsResult terms(String field, int size, String query, String filter, Ti | |
); | ||
} | ||
|
||
public TermsResult terms(String field, int size, String query, String filter, TimeRange range) { | ||
return terms(field, size, query, filter, range, "descending"); | ||
} | ||
|
||
public TermsResult terms(String field, int size, String query, TimeRange range) { | ||
return terms(field, size, query, null, range); | ||
return terms(field, size, query, null, range, "descending"); | ||
} | ||
|
||
public TermsStatsResult termsStats(String keyField, String valueField, TermsStatsOrder order, int size, String query, String filter, TimeRange range) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use a string for
sorting
here butSorting.Direction
instead.