# How to sort bucket terms in a nested aggregation on score instead of doc count? (Nested field aggregation not allowed with nested field query)

**URL:** <https://discuss.elastic.co/t/how-to-sort-bucket-terms-in-a-nested-aggregation-on-score-instead-of-doc-count-nested-field-aggregation-not-allowed-with-nested-field-query/120547>\
**Category:** Elasticsearch\
**Created:** [February 20, 2018, 2:28am UTC](https://discuss.elastic.co/t/how-to-sort-bucket-terms-in-a-nested-aggregation-on-score-instead-of-doc-count-nested-field-aggregation-not-allowed-with-nested-field-query/120547 "2018-02-20T02:28:37Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 20, 2018, 10:11pm UTC](https://discuss.elastic.co/t/how-to-sort-bucket-terms-in-a-nested-aggregation-on-score-instead-of-doc-count-nested-field-aggregation-not-allowed-with-nested-field-query/120547/3 "2018-02-20T22:11:43Z")

</div>

Read [this](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and specifically the "Also be patient" part.

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Could you also provide the current output and the expected output?  
I don't think you can order terms bucket by score as score does not make sense in a Terms Agg IMHO.

---

_[View the full topic](https://discuss.elastic.co/t/how-to-sort-bucket-terms-in-a-nested-aggregation-on-score-instead-of-doc-count-nested-field-aggregation-not-allowed-with-nested-field-query/120547)._
