Skip to content
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

Merged
merged 3 commits into from Mar 6, 2017
Merged

Update Terms Method to Support Ascending and Descending Ordering #3540

merged 3 commits into from Mar 6, 2017

Conversation

billmurrin
Copy link
Contributor

@billmurrin billmurrin commented Feb 23, 2017

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?

  • The same changes are employed in my plugin, the Quick Values Plus Widget, which provides ascending and descending ordering options.
  • The testTerms test (based on the same method) successfully passed.
  • The changes should have no impact as methods were created to ensure backwards compatibility

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@CLAassistant
Copy link

CLAassistant commented Feb 23, 2017

CLA assistant check
All committers have signed the CLA.

@@ -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) {
Copy link
Contributor

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.

@joschi joschi added the feature label Feb 23, 2017
if (size == 0) {
size = 50;
}

if (sorting == Sorting.Direction.DESC){
termsOrder = Terms.Order.count(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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))

@joschi joschi self-assigned this Mar 6, 2017
Copy link
Contributor

@joschi joschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@joschi joschi added this to the 2.3.0 milestone Mar 6, 2017
@joschi joschi merged commit bbeefdd into Graylog2:master Mar 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants