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

SQL: Allow ordering of groups based on aggregates #35118

Closed
costin opened this issue Oct 31, 2018 · 6 comments
Closed

SQL: Allow ordering of groups based on aggregates #35118

costin opened this issue Oct 31, 2018 · 6 comments

Comments

@costin
Copy link
Member

costin commented Oct 31, 2018

Due to the way composite aggs are currently implemented, one can sort only by the its keys. This is limiting as a good portion of use cases need to do just that:
GROUP BY countries ORDER BY COUNT(*)

@TimHeckel
Copy link
Contributor

This would be so beneficial -- is this planned for 6.6.0? I haven't tried, but I assume it's not baked in 6.5.0 correct? I know it's not working in 6.4.1.

@alexfrancoeur
Copy link

@costin also interested, is this something we're still targeting for 6.6?

@costin
Copy link
Member Author

costin commented Dec 12, 2018

No, there was too much work for this to make it into 6.6; it will be addressed in a future version.

@jasontedor jasontedor added v6.7.0 and removed v6.6.0 labels Dec 19, 2018
costin added a commit to costin/elasticsearch that referenced this issue Jan 30, 2019
Introduce client-side, custom sorting of groups based on aggregate
functions. To allow this, the Analyzer has been extended to push down
to underlying Aggregate, aggregate function and the Querier has been
extended to identify the case and consume the results in order and sort
them based on the given columns.
The underlying QueryContainer has been slightly modified to allow a view
of the underlying values being extracted as the columns used for sorting
might not be requested by the user.

The PR also adds minor tweaks, mainly related to tree output.

Close elastic#35118
@Kels
Copy link

Kels commented Feb 1, 2019

Is there a workaround ? Canvas seems hard to use without the possibility to limit results after an order by counting

costin added a commit that referenced this issue Feb 1, 2019
Introduce client-side sorting of groups based on aggregate
functions. To allow this, the Analyzer has been extended to push down
to underlying Aggregate, aggregate function and the Querier has been
extended to identify the case and consume the results in order and sort
them based on the given columns.
The underlying QueryContainer has been slightly modified to allow a view
of the underlying values being extracted as the columns used for sorting
might not be requested by the user.

The PR also adds minor tweaks, mainly related to tree output.

Close #35118
@alexfrancoeur
Copy link

Nice @costin !👌

costin added a commit to costin/elasticsearch that referenced this issue Feb 2, 2019
Introduce client-side sorting of groups based on aggregate
functions. To allow this, the Analyzer has been extended to push down
to underlying Aggregate, aggregate function and the Querier has been
extended to identify the case and consume the results in order and sort
them based on the given columns.
The underlying QueryContainer has been slightly modified to allow a view
of the underlying values being extracted as the columns used for sorting
might not be requested by the user.

The PR also adds minor tweaks, mainly related to tree output.

Close elastic#35118

(cherry picked from commit 783c9ed)
costin added a commit that referenced this issue Feb 2, 2019
Introduce client-side sorting of groups based on aggregate
functions. To allow this, the Analyzer has been extended to push down
to underlying Aggregate, aggregate function and the Querier has been
extended to identify the case and consume the results in order and sort
them based on the given columns.
The underlying QueryContainer has been slightly modified to allow a view
of the underlying values being extracted as the columns used for sorting
might not be requested by the user.

The PR also adds minor tweaks, mainly related to tree output.

Close #35118

(cherry picked from commit 783c9ed)
@aananthagovindarajan
Copy link

aananthagovindarajan commented Mar 3, 2020

Composite Aggregation is a very nice feature, it allows to paginate over the distinct values of the field but however sort by only "key/term". Are there any plans to support sort by doc_count desc? Also the Composite Aggregation docs, is not capturing the absence of "sort by doc_count desc" support which the majority of the users are interested in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants