# Bulked script error: "Only sibling pipeline aggregations are allowed at the top level", and how to add scripts to my json input on my visualization

**URL:** https://discuss.elastic.co/t/bulked-script-error-only-sibling-pipeline-aggregations-are-allowed-at-the-top-level-and-how-to-add-scripts-to-my-json-input-on-my-visualization/165978
**Category:** Elasticsearch
**Tags:** painless
**Created:** [January 28, 2019, 10:30am UTC](https://discuss.elastic.co/t/bulked-script-error-only-sibling-pipeline-aggregations-are-allowed-at-the-top-level-and-how-to-add-scripts-to-my-json-input-on-my-visualization/165978 "2019-01-28T10:30:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Celso\_Agra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/celso_agra/32/40272_2.png) [@Celso\_Agra](https://discuss.elastic.co/u/Celso_Agra)
#### Post date: [January 28, 2019, 10:30am UTC](https://discuss.elastic.co/t/bulked-script-error-only-sibling-pipeline-aggregations-are-allowed-at-the-top-level-and-how-to-add-scripts-to-my-json-input-on-my-visualization/165978/1 "2019-01-28T10:30:42Z")

</div>

I'm new on elasticsearch and painless language.

I'm trying to understand what kind of error is occuring and why, is that occurs.

Here is my code, below:

```
GET club/_search
{
    "query" : {
        "match_all": {}
    },
    "aggs" : {
        "total" : {
        	"value_count" : {
        		"field" : "is_member"
        	}
        },
        "total_of_members" : {
            "sum" : {
                "script" : {
                   "source": "doc['is_member'].value ? 1 : 0"
                }
            }
        },
        "total_percentage_of_members": {
          "bucket_script": {
              "buckets_path": {
                "total_members": "total_of_members",
                "total_all": "total"
              },
              "script": "params.total_members / params.total_all * 100"
          }
        }
    }
}

```

When I run this example, I got an message error:  
`Invalid pipeline aggregation named [total_percentage_of_members] of type [bucket_script]. Only sibling pipeline aggregations are allowed at the top level`

But, when I just remove `total_percentage_of_members`, everything works fine.

I tried to create a nested structure of aggs, but I'm still getting error. Does anyone can help me?

Also,

would be possible to add this script to my "JSON Input" on my visualizations?

---

<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: [February 25, 2019, 10:31am UTC](https://discuss.elastic.co/t/bulked-script-error-only-sibling-pipeline-aggregations-are-allowed-at-the-top-level-and-how-to-add-scripts-to-my-json-input-on-my-visualization/165978/2 "2019-02-25T10:31:05Z")

</div>

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