# Elasticsearch Bucket script aggregation is not working with filter aggregation

**URL:** <https://discuss.elastic.co/t/elasticsearch-bucket-script-aggregation-is-not-working-with-filter-aggregation/287273>\
**Category:** Elasticsearch\
**Created:** [October 21, 2021, 8:31am UTC](https://discuss.elastic.co/t/elasticsearch-bucket-script-aggregation-is-not-working-with-filter-aggregation/287273 "2021-10-21T08:31:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![r.ganeshbabu](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@r.ganeshbabu](https://discuss.elastic.co/u/r.ganeshbabu)\
**Post date:** [October 21, 2021, 8:31am UTC](https://discuss.elastic.co/t/elasticsearch-bucket-script-aggregation-is-not-working-with-filter-aggregation/287273/1 "2021-10-21T08:31:17Z")

</div>

Hi All,

I am trying to calculate the percentage in Elasticsearch using bucket script and below is the query I have tried it in kibana,

```auto

{
	"size": 0,
	"aggs": {
		"Bits": {
			"filters": {
				"filters": {
					"ItemBits": {
						"match": {
							"itemname": "bits"
						}
					}
				}
			},
			"aggs": {
				"value_max": {
					"max": {
						"field": "value"
					}
				}
			}
		},
		"Speed": {
			"filters": {
				"filters": {
					"ItemSpeed": {
						"match": {
							"itemname": "speed"
						}
					}
				}
			},
			"aggs": {
				"value_max": {
					"max": {
						"field": "value"
					}
				}
			}
		},
		"Bandwidth-percentage": {
			"bucket_script": {
				"buckets_path": {
					"TotalSpeed": "Speed>value_max",
					"TotalBits": "Bits>value_max"
				},
				"script": "params.TotalSpeed / params.TotalBits * 100"
			}
		}
	}
}

```

and I am getting the below error when I executed,

```auto
{
"error" : {
"root_cause" : [
{
"type" : "aggregation_execution_exception",
"reason" : "Invalid pipeline aggregation named [Bandwidth-percentage] of type [bucket_script]. Only sibling pipeline aggregations are allowed at the top level"
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [
{
"shard" : 0,
"index" : "getzabbixkpi",
"node" : "uyi22v7aR3i8MqdlxaX3jg",
"reason" : {
"type" : "aggregation_execution_exception",
"reason" : "Invalid pipeline aggregation named [Bandwidth-percentage] of type [bucket_script]. Only sibling pipeline aggregations are allowed at the top level"
}
}
]
},
"status" : 500

```

Please correct me If I am doing anything wrong.

Thanks,  
Ganeshbabu R

---

<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:** [November 18, 2021, 8:32am UTC](https://discuss.elastic.co/t/elasticsearch-bucket-script-aggregation-is-not-working-with-filter-aggregation/287273/2 "2021-11-18T08:32:09Z")

</div>

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