# Sorting a percentile aggregation

**URL:** <https://discuss.elastic.co/t/sorting-a-percentile-aggregation/273298>\
**Category:** Elasticsearch\
**Created:** [May 18, 2021, 1:58pm UTC](https://discuss.elastic.co/t/sorting-a-percentile-aggregation/273298 "2021-05-18T13:58:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chapmantrain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chapmantrain/32/22646_2.png) [@chapmantrain](https://discuss.elastic.co/u/chapmantrain)\
**Post date:** [May 18, 2021, 1:58pm UTC](https://discuss.elastic.co/t/sorting-a-percentile-aggregation/273298/1 "2021-05-18T13:58:33Z")

</div>

Is it possible to sort a percentile aggregation? The query is:

```auto
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "dttm": {
              "gte": "now-24h",
              "lte": "now"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "resources": {
      "terms": {
        "field": "displayname.keyword",
        "size": 1000
      },
      "aggs": {
        "90_inpeak": {
          "percentiles": {
            "field": "inpeak_util",
            "percents": [
              90
            ]
          }
        },
        "per_sort": {
          "bucket_sort": {
            "sort": [
              {
                "90_inpeak": {
                  "order": "desc"
                }
              }
            ]
          }
        }
      }
    }
  }
}

```

The error on the return is:

```auto
{
  "error": {
    "root_cause": [],
    "type": "search_phase_execution_exception",
    "reason": "",
    "phase": "fetch",
    "grouped": true,
    "failed_shards": [],
    "caused_by": {
      "type": "aggregation_execution_exception",
      "reason": "buckets_path must reference either a number value or a single value numeric metric aggregation, got: org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentiles"
    }
  },
  "status": 503
}

```

TIA

---

<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:** [June 15, 2021, 1:58pm UTC](https://discuss.elastic.co/t/sorting-a-percentile-aggregation/273298/2 "2021-06-15T13:58:37Z")

</div>

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