{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/14656","repository_url":"https://api.github.com/repos/elastic/elasticsearch","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/14656/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/14656/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/14656/events","html_url":"https://github.com/elastic/elasticsearch/issues/14656","id":116122988,"number":14656,"title":"'bucket_script' not supported as a top-level aggregation?","user":{"login":"davmrtl","id":233767,"avatar_url":"https://avatars.githubusercontent.com/u/233767?v=3","gravatar_id":"","url":"https://api.github.com/users/davmrtl","html_url":"https://github.com/davmrtl","followers_url":"https://api.github.com/users/davmrtl/followers","following_url":"https://api.github.com/users/davmrtl/following{/other_user}","gists_url":"https://api.github.com/users/davmrtl/gists{/gist_id}","starred_url":"https://api.github.com/users/davmrtl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davmrtl/subscriptions","organizations_url":"https://api.github.com/users/davmrtl/orgs","repos_url":"https://api.github.com/users/davmrtl/repos","events_url":"https://api.github.com/users/davmrtl/events{/privacy}","received_events_url":"https://api.github.com/users/davmrtl/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Aggregations","name":":Aggregations","color":"009800"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/discuss","name":"discuss","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2015-11-10T14:59:31Z","updated_at":"2016-10-13T10:12:07Z","closed_at":null,"body":"Hi,\r\n\r\nWhy is the 'bucket_script' not supported as a top-level aggregation?\r\n\r\nI have to produce a top-level ratio of sums... The following code gives me an error:\r\n```\r\nGET /sales-2015.11.*/sale/_search\r\n{\r\n  \"query\": {\r\n    \"match_all\": {}\r\n  },\r\n  \"aggs\": {\r\n    \"per_day\": {\r\n      \"date_histogram\": {\r\n        \"field\": \"@timestamp\",\r\n        \"interval\": \"day\"\r\n      },\r\n      \"aggs\": {\r\n        \"sum_of_sales\": {\r\n          \"sum\": {\r\n            \"field\": \"sales\"\r\n          }\r\n        },\r\n        \"sum_of_vendors_count\": {\r\n          \"sum\": {\r\n            \"field\": \"vendors_count\"\r\n          }\r\n        },\r\n        \"ratio_of_sales_per_vendors_count\": {\r\n          \"bucket_script\": {\r\n            \"buckets_path\": {\r\n              \"sum_of_sales\": \"sum_of_sales\",\r\n              \"sum_of_vendors_count\": \"sum_of_vendors_count\"\r\n            },\r\n            \"script\": \"sum_of_sales / sum_of_vendors_count\"\r\n          }\r\n        }\r\n      }\r\n    },\r\n    \"sum_of_all_sales\": {\r\n      \"sum\": {\r\n        \"field\": \"sales\"\r\n      }\r\n    },\r\n    \"sum_of_all_vendors_count\": {\r\n      \"sum\": {\r\n        \"field\": \"vendors_count\"\r\n      }\r\n    },\r\n\t\"ratio_of_all_sales_per_all_vendors_count\": {\r\n\t  \"bucket_script\": {\r\n\t    \"buckets_path\": {\r\n\t      \"sum_of_all_sales\": \"sum_of_all_sales\",\r\n\t      \"sum_of_all_vendors_count\": \"sum_of_all_vendors_count\"\r\n\t    },\r\n\t    \"script\": \"sum_of_all_sales / sum_of_all_vendors_count\"\r\n\t  }\r\n  \t}\r\n  },\r\n  \"size\": 0\r\n}\r\n```\r\nIt gives me the following error:\r\n```\r\n{\r\n   \"error\": {\r\n      \"root_cause\": [\r\n         {\r\n            \"type\": \"aggregation_execution_exception\",\r\n            \"reason\": \"Invalid pipeline aggregation named [ratio_of_all_sales_per_all_vendors_count] of type [bucket_script]. Only sibling pipeline aggregations are allowed at the top level\"\r\n         }\r\n      ],\r\n      \"type\": \"search_phase_execution_exception\",\r\n      \"reason\": \"all shards failed\",\r\n      \"phase\": \"query\",\r\n      \"grouped\": true,\r\n      \"failed_shards\": [\r\n         {\r\n            \"shard\": 0,\r\n            \"index\": \"sales-2015.11.01\",\r\n            \"node\": \"N3_ZEgs-RAGPOssZrCcL_w\",\r\n            \"reason\": {\r\n               \"type\": \"aggregation_execution_exception\",\r\n               \"reason\": \"Invalid pipeline aggregation named [ratio_of_all_sales_per_all_vendors_count] of type [bucket_script]. Only sibling pipeline aggregations are allowed at the top level\"\r\n            }\r\n         }\r\n      ]\r\n   },\r\n   \"status\": 500\r\n}\r\n```\r\nHow can I get it working?\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/253472692","html_url":"https://github.com/elastic/elasticsearch/issues/14656#issuecomment-253472692","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/14656","id":253472692,"user":{"login":"ebuildy","id":1219817,"avatar_url":"https://avatars.githubusercontent.com/u/1219817?v=3","gravatar_id":"","url":"https://api.github.com/users/ebuildy","html_url":"https://github.com/ebuildy","followers_url":"https://api.github.com/users/ebuildy/followers","following_url":"https://api.github.com/users/ebuildy/following{/other_user}","gists_url":"https://api.github.com/users/ebuildy/gists{/gist_id}","starred_url":"https://api.github.com/users/ebuildy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ebuildy/subscriptions","organizations_url":"https://api.github.com/users/ebuildy/orgs","repos_url":"https://api.github.com/users/ebuildy/repos","events_url":"https://api.github.com/users/ebuildy/events{/privacy}","received_events_url":"https://api.github.com/users/ebuildy/received_events","type":"User","site_admin":false},"created_at":"2016-10-13T10:12:07Z","updated_at":"2016-10-13T10:12:07Z","body":"@claudio-viola did you try to use https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-aggregations-bucket-global-aggregation.html? "}}
{"actor":{"display_login":"ebuildy"}}