# Error while sorting in bucket aggregation

**URL:** <https://discuss.elastic.co/t/error-while-sorting-in-bucket-aggregation/237912>\
**Category:** Elasticsearch\
**Created:** [June 20, 2020, 11:37am UTC](https://discuss.elastic.co/t/error-while-sorting-in-bucket-aggregation/237912 "2020-06-20T11:37:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daud\_Ahmed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daud_ahmed/32/65655_2.png) [@Daud\_Ahmed](https://discuss.elastic.co/u/Daud_Ahmed)\
**Post date:** [June 20, 2020, 11:37am UTC](https://discuss.elastic.co/t/error-while-sorting-in-bucket-aggregation/237912/1 "2020-06-20T11:37:28Z")

</div>

```auto
  {

        "error": {

            "root_cause": [

                {

                    "type": "aggregation_execution_exception",

                    "reason": "Invalid aggregator order path [data.hardware.ram_usage]. The provided aggregation [data.hardware] either does not exist, or is a pipeline aggregation and cannot be used to sort the buckets."

                },

                {

                    "type": "aggregation_execution_exception",

                    "reason": "Invalid aggregator order path [data.hardware.ram_usage]. The provided aggregation [data.hardware] either does not exist, or is a pipeline aggregation and cannot be used to sort the buckets."

                }

            ],

            "type": "search_phase_execution_exception",

            "reason": "all shards failed",

```

My query is

```auto
{
	"aggs": {
		"2": {
			"terms": {
				"field": "agent.name",
				"size": 5,
				"order": {
							"data.hardware.ram_usage": "desc"
						}
			},
			"aggs": {
				"3": {
					"terms": {
						"field": "data.hardware.ram_usage",
						"size": 1,
						"order": {
							"_count": "desc"
						}
					}
				}
			}
		}
	},
	"size": 0,
	"_source": {
		"excludes": [
			"@timestamp"
		]
	},
	"query": {
		"bool": {
			"must": [
				{
					"match_all": {}
				},
				{
					"exists": {
						"field": "data.hardware.ram_usage"
					}
				}
			]
		}
	}
}

```

What i want to do is get 5 **agent.name** which have the largest **data.hardware.ram\_usage** value.

Can someone help me with this?

---

<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:** [July 18, 2020, 11:37am UTC](https://discuss.elastic.co/t/error-while-sorting-in-bucket-aggregation/237912/2 "2020-07-18T11:37:35Z")

</div>

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