{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/42046","repository_url":"https://api.github.com/repos/elastic/elasticsearch","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/42046/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/42046/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/42046/events","html_url":"https://github.com/elastic/elasticsearch/issues/42046","id":442466736,"node_id":"MDU6SXNzdWU0NDI0NjY3MzY=","number":42046,"title":"Include user parameters in painless reduce script context","user":{"login":"nbrahms","id":2490631,"node_id":"MDQ6VXNlcjI0OTA2MzE=","avatar_url":"https://avatars3.githubusercontent.com/u/2490631?v=4","gravatar_id":"","url":"https://api.github.com/users/nbrahms","html_url":"https://github.com/nbrahms","followers_url":"https://api.github.com/users/nbrahms/followers","following_url":"https://api.github.com/users/nbrahms/following{/other_user}","gists_url":"https://api.github.com/users/nbrahms/gists{/gist_id}","starred_url":"https://api.github.com/users/nbrahms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nbrahms/subscriptions","organizations_url":"https://api.github.com/users/nbrahms/orgs","repos_url":"https://api.github.com/users/nbrahms/repos","events_url":"https://api.github.com/users/nbrahms/events{/privacy}","received_events_url":"https://api.github.com/users/nbrahms/received_events","type":"User","site_admin":false},"labels":[{"id":146834791,"node_id":"MDU6TGFiZWwxNDY4MzQ3OTE=","url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Core/Infra/Scripting","name":":Core/Infra/Scripting","color":"0e8a16","default":false,"description":"Scripting abstractions, Painless, and Mustache"},{"id":23173,"node_id":"MDU6TGFiZWwyMzE3Mw==","url":"https://api.github.com/repos/elastic/elasticsearch/labels/%3Ebug","name":">bug","color":"b60205","default":false,"description":null}],"state":"closed","locked":false,"assignee":{"login":"jdconrad","id":2126764,"node_id":"MDQ6VXNlcjIxMjY3NjQ=","avatar_url":"https://avatars2.githubusercontent.com/u/2126764?v=4","gravatar_id":"","url":"https://api.github.com/users/jdconrad","html_url":"https://github.com/jdconrad","followers_url":"https://api.github.com/users/jdconrad/followers","following_url":"https://api.github.com/users/jdconrad/following{/other_user}","gists_url":"https://api.github.com/users/jdconrad/gists{/gist_id}","starred_url":"https://api.github.com/users/jdconrad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdconrad/subscriptions","organizations_url":"https://api.github.com/users/jdconrad/orgs","repos_url":"https://api.github.com/users/jdconrad/repos","events_url":"https://api.github.com/users/jdconrad/events{/privacy}","received_events_url":"https://api.github.com/users/jdconrad/received_events","type":"User","site_admin":false},"assignees":[{"login":"jdconrad","id":2126764,"node_id":"MDQ6VXNlcjIxMjY3NjQ=","avatar_url":"https://avatars2.githubusercontent.com/u/2126764?v=4","gravatar_id":"","url":"https://api.github.com/users/jdconrad","html_url":"https://github.com/jdconrad","followers_url":"https://api.github.com/users/jdconrad/followers","following_url":"https://api.github.com/users/jdconrad/following{/other_user}","gists_url":"https://api.github.com/users/jdconrad/gists{/gist_id}","starred_url":"https://api.github.com/users/jdconrad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdconrad/subscriptions","organizations_url":"https://api.github.com/users/jdconrad/orgs","repos_url":"https://api.github.com/users/jdconrad/repos","events_url":"https://api.github.com/users/jdconrad/events{/privacy}","received_events_url":"https://api.github.com/users/jdconrad/received_events","type":"User","site_admin":false}],"milestone":null,"comments":6,"created_at":"2019-05-09T22:45:46Z","updated_at":"2019-12-19T07:09:24Z","closed_at":"2019-05-23T23:01:58Z","author_association":"NONE","body":"Hello,\r\n\r\nI'd like to request that script parameters be available in scripted metric reduce scripts.\r\n\r\nHere's a toy example:\r\n```\r\nGET foo/_search\r\n{\r\n  \"query\" : {\r\n    \"match_all\": {}\r\n  },\r\n  \"size\": 0,\r\n  \"aggregations\": {\r\n    \"foo\": {\r\n      \"scripted_metric\": {\r\n        \"params\": {\r\n          \"foo\": 2\r\n        },\r\n        \"init_script\": \"state.bla = 0\",\r\n        \"map_script\": \"state.bla += 2\",\r\n        \"combine_script\": \"return state.bla\",\r\n        \"reduce_script\": \"int r = 0; for (s in states) r += s; return r * params.foo\"\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nwhich returns:\r\n```\r\n{\r\n  \"error\": {\r\n    \"root_cause\": [],\r\n    \"type\": \"search_phase_execution_exception\",\r\n    \"reason\": \"\",\r\n    \"phase\": \"fetch\",\r\n    \"grouped\": true,\r\n    \"failed_shards\": [],\r\n    \"caused_by\": {\r\n      \"type\": \"script_exception\",\r\n      \"reason\": \"runtime error\",\r\n      \"script_stack\": [\r\n        \"return r * params.foo\",\r\n        \"                 ^---- HERE\"\r\n      ],\r\n      \"script\": \"int r = 0; for (s in states) r += s; return r * params.foo\",\r\n      \"lang\": \"painless\",\r\n      \"caused_by\": {\r\n        \"type\": \"null_pointer_exception\",\r\n        \"reason\": null\r\n      }\r\n    }\r\n  },\r\n  \"status\": 503\r\n}\r\n```\r\n\r\nIMO it should be pretty common to parameterize reduction (in my case, I want to control a final sort order). Can we throw this on the roadmap?\r\n"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/567365233","html_url":"https://github.com/elastic/elasticsearch/issues/42046#issuecomment-567365233","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/42046","id":567365233,"node_id":"MDEyOklzc3VlQ29tbWVudDU2NzM2NTIzMw==","user":{"login":"booster96","id":13223079,"node_id":"MDQ6VXNlcjEzMjIzMDc5","avatar_url":"https://avatars3.githubusercontent.com/u/13223079?v=4","gravatar_id":"","url":"https://api.github.com/users/booster96","html_url":"https://github.com/booster96","followers_url":"https://api.github.com/users/booster96/followers","following_url":"https://api.github.com/users/booster96/following{/other_user}","gists_url":"https://api.github.com/users/booster96/gists{/gist_id}","starred_url":"https://api.github.com/users/booster96/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/booster96/subscriptions","organizations_url":"https://api.github.com/users/booster96/orgs","repos_url":"https://api.github.com/users/booster96/repos","events_url":"https://api.github.com/users/booster96/events{/privacy}","received_events_url":"https://api.github.com/users/booster96/received_events","type":"User","site_admin":false},"created_at":"2019-12-19T07:09:24Z","updated_at":"2019-12-19T07:09:24Z","author_association":"NONE","body":"how can I use some aggregated value(for ex some of any column) which is outside scripted_metric and then use that value in params.foo inside scripted_metric. Please advice"}}
{"actor":{"display_login":"booster96"}}