# How to sort keyword/text fields on aggregation results

**URL:** <https://discuss.elastic.co/t/how-to-sort-keyword-text-fields-on-aggregation-results/301160>\
**Category:** Elasticsearch\
**Created:** [March 31, 2022, 5:51am UTC](https://discuss.elastic.co/t/how-to-sort-keyword-text-fields-on-aggregation-results/301160 "2022-03-31T05:51:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shushil\_Shankar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shushil_shankar/32/84391_2.png) [@Shushil\_Shankar](https://discuss.elastic.co/u/Shushil_Shankar)\
**Post date:** [March 31, 2022, 5:51am UTC](https://discuss.elastic.co/t/how-to-sort-keyword-text-fields-on-aggregation-results/301160/1 "2022-03-31T05:51:48Z")

</div>

Hi Everyone!

I have a aggregation results and I need to sort aggregation data using [Elasticsearch.Net](http://Elasticsearch.Net). When i'm trying using terms aggregation i'm getting this error "buckets\_path must reference either a number value or a single value numeric metric aggregation, got: [UnmappedTerms] at aggregation".

Numeric columns are sorting correctly.

Here my query i'm using in ES head:

```auto
{
  "track_total_hits": true,
  "aggs": {
    "UniqueJobs": {
      "aggs": {
        "top_grades": {
          "top_hits": {
            "size": 1,
            "_source": {
              "includes": [
                "assetId",
                "jobId",
                "name",
                
              ]
            }
          }
        },
        "commits": {
          "terms": {
            "field": "name",
            "size": 10000
          }
        },
        "bucket_sort": {
          "bucket_sort": {
            "from": 0,
            "size": 50,
            "sort": [
              {
                "commits": {
                  "order": "asc"
                }
              }
            ]
          }
        }
      },
      "terms": {
        "field": "JobId",
        "size": 100000
      }
    }
  },
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "analyze_wildcard": true,
            "default_operator": "and",
            "query": "John AND test AND portfolio*"
          }
        }
      ]
    }
  }
}

```

Thanks in advance!

---

<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:** [April 28, 2022, 5:52am UTC](https://discuss.elastic.co/t/how-to-sort-keyword-text-fields-on-aggregation-results/301160/2 "2022-04-28T05:52:46Z")

</div>

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