-
Notifications
You must be signed in to change notification settings - Fork 1.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
Conversation
@@ -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) { |
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 but Sorting.Direction
instead.
if (size == 0) { | ||
size = 50; | ||
} | ||
|
||
if (sorting == Sorting.Direction.DESC){ | ||
termsOrder = Terms.Order.count(false); |
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.
Why not Terms.Order#term(boolean)
here?
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.
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
Ordering the buckets by their doc_count in an ascending manner:
AggregationBuilders
.terms("genders")
.field("gender")
.order(Terms.Order.count(true))
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.
LGTM. 👍
Add sort order to the terms method (org.graylog2.indexer.searches.Searches) in order to provide support for ascending and descending Terms aggregation results. Relying on widgets to conduct the ascending order does not provide a "true bottom" value, it only provides the most ascending result based on a descending pull; if the possible results are greater than the size of the pull (e.g. 50) this will result in an inaccurate and misleading result.
Description
The changes provide a sorting variable to the terms method. Subsequent functions for the method were modified to pass a default value of "descending" into the method in order to assure backwards compatibility. The changes passed the "testTerms" Test.
Motivation and Context
This change is required to provide true ascending, or bottom, values for term based aggregations.
Relates to Issue #2459
How Has This Been Tested?
Types of changes
Checklist: