{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/15670","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/15670/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/15670/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/15670/events","html_url":"https://github.com/elastic/elasticsearch/issues/15670","id":123914128,"number":15670,"title":"Ability to set percentage influence of each function in function score query","user":{"login":"Vineeth-Mohan","id":977962,"avatar_url":"https://avatars.githubusercontent.com/u/977962?v=3","gravatar_id":"","url":"https://api.github.com/users/Vineeth-Mohan","html_url":"https://github.com/Vineeth-Mohan","followers_url":"https://api.github.com/users/Vineeth-Mohan/followers","following_url":"https://api.github.com/users/Vineeth-Mohan/following{/other_user}","gists_url":"https://api.github.com/users/Vineeth-Mohan/gists{/gist_id}","starred_url":"https://api.github.com/users/Vineeth-Mohan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vineeth-Mohan/subscriptions","organizations_url":"https://api.github.com/users/Vineeth-Mohan/orgs","repos_url":"https://api.github.com/users/Vineeth-Mohan/repos","events_url":"https://api.github.com/users/Vineeth-Mohan/events{/privacy}","received_events_url":"https://api.github.com/users/Vineeth-Mohan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/feedback_needed","name":"feedback_needed","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-26T06:57:16Z","updated_at":"2016-01-08T08:19:59Z","closed_at":null,"body":"The functions score query gives a good facility to implement various aspects of the score , but then its not exactly giving control over the influence of each function.\r\nFor eg: , for the function below - \r\n```\r\n{\r\n  \"query\": {\r\n    \"function_score\": {\r\n      \"functions\": [\r\n        {\r\n          \"decay\": {\r\n            \"gauss\": {\r\n              \"date\": {\r\n                \"origin\": \"2013-09-17\",\r\n                \"scale\": \"10d\",\r\n                \"offset\": \"5d\",\r\n                \"decay\": 0.5\r\n              }\r\n            }\r\n          }\r\n        },\r\n        {\r\n          \"field_value_factor\": {\r\n            \"field\": \"popularity\",\r\n            \"factor\": 1.2,\r\n            \"modifier\": \"sqrt\",\r\n            \"missing\": 1\r\n          }\r\n        },\r\n        {\r\n          \"random_score\": {}\r\n        },\r\n        {\r\n          \"script_score\": {\r\n            \"script\": {\r\n              \"lang\": \"lang\",\r\n              \"params\": {\r\n                \"param1\": 2,\r\n                \"param2\": 3\r\n              },\r\n              \"inline\": \"_score * doc['rating'].value / pow(param1, param2)\"\r\n            }\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  }\r\n}\r\n```\r\nThere are 4 functions and they dictate the end score. Here , either of the function like the script_score function can eat up all the influence of the score. That is the value of the script_score might be in range of 1000 to 2000 and value of the decay would be between 0 and 1. Hence the influence of the decay function is not exactly passed on to the final score , rather its the script_score that eats up all the influence , rest of the functions might have little or no influence on the final score. \r\n\r\nTo fix this , it might be useful to have a influenceScore factor per function which tells what percentage of the end score , this function should influence.\r\nFor eg: , the above query can be rewriten as\r\n\r\n```\r\n{\r\n  \"query\": {\r\n    \"function_score\": {\r\n      \"functions\": [\r\n        {\r\n          \"influenceScore\": \"40%\",\r\n          \"decay\": {\r\n            \"gauss\": {\r\n              \"date\": {\r\n                \"origin\": \"2013-09-17\",\r\n                \"scale\": \"10d\",\r\n                \"offset\": \"5d\",\r\n                \"decay\": 0.5\r\n              }\r\n            }\r\n          }\r\n        },\r\n        {\r\n          \"influenceScore\": \"30%\",\r\n          \"field_value_factor\": {\r\n            \"field\": \"popularity\",\r\n            \"factor\": 1.2,\r\n            \"modifier\": \"sqrt\",\r\n            \"missing\": 1\r\n          }\r\n        },\r\n        {\r\n          \"influenceScore\": \"10%\",\r\n          \"random_score\": {}\r\n        },\r\n        {\r\n          \"influenceScore\": \"20%\",\r\n          \"script_score\": {\r\n            \"script\": {\r\n              \"lang\": \"lang\",\r\n              \"params\": {\r\n                \"param1\": 2,\r\n                \"param2\": 3\r\n              },\r\n              \"inline\": \"_score * doc['rating'].value / pow(param1, param2)\"\r\n            }\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  }\r\n}\r\n```\r\nHere , we will have a influenceScore per function which dictates the influence of each function. This will help us in further fine tuning the score.\r\n"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/169929371","html_url":"https://github.com/elastic/elasticsearch/issues/15670#issuecomment-169929371","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/15670","id":169929371,"user":{"login":"s1monw","id":973334,"avatar_url":"https://avatars.githubusercontent.com/u/973334?v=3","gravatar_id":"","url":"https://api.github.com/users/s1monw","html_url":"https://github.com/s1monw","followers_url":"https://api.github.com/users/s1monw/followers","following_url":"https://api.github.com/users/s1monw/following{/other_user}","gists_url":"https://api.github.com/users/s1monw/gists{/gist_id}","starred_url":"https://api.github.com/users/s1monw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s1monw/subscriptions","organizations_url":"https://api.github.com/users/s1monw/orgs","repos_url":"https://api.github.com/users/s1monw/repos","events_url":"https://api.github.com/users/s1monw/events{/privacy}","received_events_url":"https://api.github.com/users/s1monw/received_events","type":"User","site_admin":false},"created_at":"2016-01-08T08:19:59Z","updated_at":"2016-01-08T08:19:59Z","body":"@Vineeth-Mohan I can see what you are saying and I admit it can be challenging. I personally don't see a good way to apply a general way of normalization here. I see the function score feature as a toolset of primitives that lets / forces the user to ensure that each element of the equation has it's relevant weight etc. I wonder if other ie. @brwe has some ideas?"}}