{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/15921","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/15921/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/15921/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/15921/events","html_url":"https://github.com/elastic/elasticsearch/issues/15921","id":126128478,"number":15921,"title":"function_score ignores functions if inner query is filter-only","user":{"login":"micpalmia","id":663003,"avatar_url":"https://avatars.githubusercontent.com/u/663003?v=3","gravatar_id":"","url":"https://api.github.com/users/micpalmia","html_url":"https://github.com/micpalmia","followers_url":"https://api.github.com/users/micpalmia/followers","following_url":"https://api.github.com/users/micpalmia/following{/other_user}","gists_url":"https://api.github.com/users/micpalmia/gists{/gist_id}","starred_url":"https://api.github.com/users/micpalmia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/micpalmia/subscriptions","organizations_url":"https://api.github.com/users/micpalmia/orgs","repos_url":"https://api.github.com/users/micpalmia/repos","events_url":"https://api.github.com/users/micpalmia/events{/privacy}","received_events_url":"https://api.github.com/users/micpalmia/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Search","name":":Search","color":"009800"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/adoptme","name":"adoptme","color":"207de5"},{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/bug","name":"bug","color":"9e2c2c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2016-01-12T08:53:49Z","updated_at":"2016-01-13T10:58:34Z","closed_at":null,"body":"Working on *Elasticsearch 2.1.1* - sorry in advance for the probably inaccurate terminology.\r\n\r\nWhen the `query` section of a `function_score` query would not normally rank results (e.g., a `bool` query only containing `filter` and `must_not` clauses), the function score query ranks `0` all elements regardless of the listed `functions`.\r\n\r\nMoving the filtering to an outside query works as expected.\r\nIn Elasticsearch 1.x, a `filtered` query only containing the `filter` section gets scored normally.\r\n\r\n``` bash\r\ncurl -XPUT localhost:9200/test/test/1 -d '\r\n{\"rank\": 1}'\r\ncurl -XPUT localhost:9200/test/test/2 -d '\r\n{\"rank\": 2}'\r\ncurl -XPUT localhost:9200/test/test/3 -d '\r\n{\"rank\": 3}'\r\n\r\n# scores everything 0\r\ncurl -XPOST localhost:9200/test/test/_search -d '\r\n{\r\n   \"query\": {\r\n      \"function_score\": {\r\n         \"query\": {\r\n            \"bool\": {\r\n               \"filter\": {\r\n                  \"range\": {\r\n                     \"rank\": {\r\n                        \"gte\": 2\r\n                     }\r\n                  }\r\n               }\r\n            }\r\n         },\r\n         \"functions\": [\r\n            {\r\n               \"field_value_factor\": {\r\n                  \"field\": \"rank\"\r\n               }\r\n            }\r\n         ]\r\n      }\r\n   }\r\n}'\r\n\r\n# scores appropriately\r\ncurl -XPOST localhost:9200/test/test/_search -d '\r\n{\r\n   \"query\": {\r\n      \"bool\": {\r\n         \"filter\": {\r\n            \"range\": {\r\n               \"rank\": {\r\n                  \"gte\": 2\r\n               }\r\n            }\r\n         },\r\n         \"must\": {\r\n            \"function_score\": {\r\n               \"functions\": [\r\n                  {\r\n                     \"field_value_factor\": {\r\n                        \"field\": \"rank\"\r\n                     }\r\n                  }\r\n               ]\r\n            }\r\n         }\r\n      }\r\n   }\r\n}'\r\n```"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/171254208","html_url":"https://github.com/elastic/elasticsearch/issues/15921#issuecomment-171254208","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/15921","id":171254208,"user":{"login":"clintongormley","id":56599,"avatar_url":"https://avatars.githubusercontent.com/u/56599?v=3","gravatar_id":"","url":"https://api.github.com/users/clintongormley","html_url":"https://github.com/clintongormley","followers_url":"https://api.github.com/users/clintongormley/followers","following_url":"https://api.github.com/users/clintongormley/following{/other_user}","gists_url":"https://api.github.com/users/clintongormley/gists{/gist_id}","starred_url":"https://api.github.com/users/clintongormley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clintongormley/subscriptions","organizations_url":"https://api.github.com/users/clintongormley/orgs","repos_url":"https://api.github.com/users/clintongormley/repos","events_url":"https://api.github.com/users/clintongormley/events{/privacy}","received_events_url":"https://api.github.com/users/clintongormley/received_events","type":"User","site_admin":false},"created_at":"2016-01-13T10:58:34Z","updated_at":"2016-01-13T10:58:34Z","body":"I've added the documentation here: https://github.com/elastic/elasticsearch/commit/33e7bb6fba5bf0a28d3fb5462cff931be579c366\r\n\r\nJust wondering if the function score query should always have an implicit `match_all`, to make it function the way it did before."}}