{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/13469","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/13469/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/13469/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/13469/events","html_url":"https://github.com/elastic/elasticsearch/issues/13469","id":105812759,"number":13469,"title":"Get function score query results as fields","user":{"login":"mausch","id":95194,"avatar_url":"https://avatars.githubusercontent.com/u/95194?v=3","gravatar_id":"","url":"https://api.github.com/users/mausch","html_url":"https://github.com/mausch","followers_url":"https://api.github.com/users/mausch/followers","following_url":"https://api.github.com/users/mausch/following{/other_user}","gists_url":"https://api.github.com/users/mausch/gists{/gist_id}","starred_url":"https://api.github.com/users/mausch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mausch/subscriptions","organizations_url":"https://api.github.com/users/mausch/orgs","repos_url":"https://api.github.com/users/mausch/repos","events_url":"https://api.github.com/users/mausch/events{/privacy}","received_events_url":"https://api.github.com/users/mausch/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Scripting","name":":Scripting","color":"009800"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/enhancement","name":"enhancement","color":"4a4ea8"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/low%20hanging%20fruit","name":"low hanging fruit","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-09-10T14:03:14Z","updated_at":"2015-09-11T13:39:24Z","closed_at":null,"body":"[I asked about this a couple of weeks ago in the forum](https://discuss.elastic.co/t/get-function-score-value-as-fields/28129) and didn't get any answers, so it seems that this is not implemented at the moment, therefore this is a feature request.\r\n\r\nBasically, I need to return several function score query results as fields. Parsing the explanation tree is not really an option as it's cumbersome, error-prone, and slow (explanations bloat up the response quite a bit).\r\n\r\nThere is `script_fields` but it doesn't seem like it's possible to call arbitrary function score queries (e.g. a decay function).\r\n\r\nTo give an example, I'd like to run something like this:\r\n\r\n```json\r\n{\r\n  \"script_fields\": {\r\n    \"pepe\": {\r\n      \"random_score\": {\r\n        \"seed\": 123\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nwhere [`random_score`](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-random) could be any function score query.\r\n\r\nor alternatively being able to run any arbitrary function score as part of a script:\r\n\r\n```json\r\n{\r\n  \"script_fields\": {\r\n    \"pepe\": {\r\n      \"script\": \"function_queries.random_score(123)\"\r\n    }\r\n  }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/139548516","html_url":"https://github.com/elastic/elasticsearch/issues/13469#issuecomment-139548516","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/13469","id":139548516,"user":{"login":"nik9000","id":215970,"avatar_url":"https://avatars.githubusercontent.com/u/215970?v=3","gravatar_id":"","url":"https://api.github.com/users/nik9000","html_url":"https://github.com/nik9000","followers_url":"https://api.github.com/users/nik9000/followers","following_url":"https://api.github.com/users/nik9000/following{/other_user}","gists_url":"https://api.github.com/users/nik9000/gists{/gist_id}","starred_url":"https://api.github.com/users/nik9000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nik9000/subscriptions","organizations_url":"https://api.github.com/users/nik9000/orgs","repos_url":"https://api.github.com/users/nik9000/repos","events_url":"https://api.github.com/users/nik9000/events{/privacy}","received_events_url":"https://api.github.com/users/nik9000/received_events","type":"User","site_admin":false},"created_at":"2015-09-11T13:39:24Z","updated_at":"2015-09-11T13:39:24Z","body":"I think I'm sold. I had a voice conversation with @brwe and @colings86 about this and we came to the conclusion that:\r\n1. This is reasonably easy to do.\r\n2. It would have been useful for @brwe to have had in the past - in particular when building presentations about how the scores are built.\r\n3. Its totally possible to build this and misinterpret the results.\r\n4. In many many cases you don't want to return these results to the user. For example if you want to show a user the result that is closest to them you would want the distance from their location without any exponential decay applied. In those cases this would be trappy.\r\n5. Its possible that users may think that these values are cached between the search and fetch phase. They wouldn't be. It'd be more trouble than its worth.\r\n\r\nSo I think this is worth doing but we'll have to make sure there is a big warning. I hate those but its wroth it I think.\r\n\r\nI'm marking this as low hanging fruit because it should be reasonably simple but I don't know how its ranked relative to other things. So its probably a good thing for a new contributor to pick up.\r\n\r\nPing @clintongormley to check all this - he'll have opinions that might differ from mine and he gets to make the final call."}}