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

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?

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