# How to add sorting to multi bucket aggregation?

**URL:** <https://discuss.elastic.co/t/how-to-add-sorting-to-multi-bucket-aggregation/157440>\
**Category:** Elasticsearch\
**Created:** [November 19, 2018, 8:58pm UTC](https://discuss.elastic.co/t/how-to-add-sorting-to-multi-bucket-aggregation/157440 "2018-11-19T20:58:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomm](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@tomm](https://discuss.elastic.co/u/tomm)\
**Post date:** [November 19, 2018, 8:58pm UTC](https://discuss.elastic.co/t/how-to-add-sorting-to-multi-bucket-aggregation/157440/1 "2018-11-19T20:58:10Z")

</div>

Hi!

I have some mapping with sample data, and also query aggregating that data, that works ALMOST like I want it - thanks to "size": 1 it gets me only one variant.. but I'd like it to get cheapest, so I'm missing sorting by price.  
here's my query: [https://gist.github.com/maur/7acb7ac4f36196e6a5f251ee5289ec6a](https://gist.github.com/maur/7acb7ac4f36196e6a5f251ee5289ec6a)

I tried in "sort" putting variant-sum\>\_count, variant-sum\>sum-filter.. and many, really many other options. Is it even possible in this place to sort by summed price?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 17, 2018, 8:58pm UTC](https://discuss.elastic.co/t/how-to-add-sorting-to-multi-bucket-aggregation/157440/2 "2018-12-17T20:58:15Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
