{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/229810511","pull_request_review_id":170399587,"id":229810511,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyOTgxMDUxMQ==","diff_hunk":"@@ -75,24 +76,46 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC\n                 validationError.addValidationError(\"fetching source can not be disabled\");\n                 channel.sendResponse(new BytesRestResponse(channel, validationError));\n             } else {\n-                client.get(getRequest, new RestResponseListener<GetResponse>(channel) {\n-                    @Override\n-                    public RestResponse buildResponse(final GetResponse response) throws Exception {\n-                        final XContentBuilder builder = channel.newBuilder(request.getXContentType(), false);\n-                        // check if doc source (or doc itself) is missing\n-                        if (response.isSourceEmpty()) {\n-                            return new BytesRestResponse(NOT_FOUND, builder);\n-                        } else {\n-                            final BytesReference source = response.getSourceInternal();\n-                            try (InputStream stream = source.streamInput()) {\n-                                builder.rawValue(stream, XContentHelper.xContentType(source));\n-                            }\n-                            return new BytesRestResponse(OK, builder);\n-                        }\n-                    }\n-                });\n+                client.get(getRequest, new RestGetSourceResponseListener(channel, request));\n             }\n         };\n     }\n \n+    static class RestGetSourceResponseListener extends RestResponseListener<GetResponse> {\n+        private final RestRequest request;\n+\n+        RestGetSourceResponseListener(RestChannel channel, RestRequest request) {\n+            super(channel);\n+            this.request = request;\n+        }\n+\n+        @Override\n+        public RestResponse buildResponse(final GetResponse response) throws Exception {\n+            checkIfSourceEmpty(response);\n+\n+            final XContentBuilder builder = channel.newBuilder(request.getXContentType(), false);\n+            final BytesReference source = response.getSourceInternal();\n+            try (InputStream stream = source.streamInput()) {\n+                builder.rawValue(stream, XContentHelper.xContentType(source));\n+            }\n+            return new BytesRestResponse(OK, builder);\n+        }\n+\n+        /**\n+         * Checks if the requested source or document itself is missing.\n+         *\n+         * @param response a response\n+         * @throws ResourceNotFoundException if source or doc itself is missing\n+         */\n+        private void checkIfSourceEmpty(final GetResponse response) {\n+            if (response.isSourceEmpty()) {","path":"server/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java","position":76,"original_position":76,"commit_id":"04fce0b4d5b0f13f267abe3bb591b9f9f055369c","original_commit_id":"04fce0b4d5b0f13f267abe3bb591b9f9f055369c","user":{"login":"nik9000","id":215970,"node_id":"MDQ6VXNlcjIxNTk3MA==","avatar_url":"https://avatars2.githubusercontent.com/u/215970?v=4","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},"body":"I'd prefer to check `isExists` first because, at least in my head, `isSourceEmpty` doesn't really make sense if the document doesn't exist. I know it *works* to do it this way, but it'd make me feel better to switch the order.","created_at":"2018-10-31T18:09:36Z","updated_at":"2018-10-31T18:10:05Z","html_url":"https://github.com/elastic/elasticsearch/pull/34083#discussion_r229810511","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/34083","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/229810511"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/34083#discussion_r229810511"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/34083"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/34083","id":218329569,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE4MzI5NTY5","html_url":"https://github.com/elastic/elasticsearch/pull/34083","diff_url":"https://github.com/elastic/elasticsearch/pull/34083.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/34083.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/34083","number":34083,"state":"open","locked":false,"title":"Raise a 404 exception when document source is not found (#33384)","user":{"login":"cbismuth","id":21545602,"node_id":"MDQ6VXNlcjIxNTQ1NjAy","avatar_url":"https://avatars1.githubusercontent.com/u/21545602?v=4","gravatar_id":"","url":"https://api.github.com/users/cbismuth","html_url":"https://github.com/cbismuth","followers_url":"https://api.github.com/users/cbismuth/followers","following_url":"https://api.github.com/users/cbismuth/following{/other_user}","gists_url":"https://api.github.com/users/cbismuth/gists{/gist_id}","starred_url":"https://api.github.com/users/cbismuth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbismuth/subscriptions","organizations_url":"https://api.github.com/users/cbismuth/orgs","repos_url":"https://api.github.com/users/cbismuth/repos","events_url":"https://api.github.com/users/cbismuth/events{/privacy}","received_events_url":"https://api.github.com/users/cbismuth/received_events","type":"User","site_admin":false},"body":"This pull request makes the `RestGetSourceAction` return a `ResourceNotFoundException` with a proper JSON response when source or document itself is missing (see issue #33384).\r\n\r\nHere is below a sample JSON output:\r\n\r\n```\r\n{\r\n  \"error\": {\r\n    \"root_cause\": [\r\n      {\r\n        \"type\": \"resource_not_found_exception\",\r\n        \"reason\": \"Document or source not found [index1]/[_doc]/[1]\"\r\n      }\r\n    ],\r\n    \"type\": \"resource_not_found_exception\",\r\n    \"reason\": \"Document or source not found [index1]/[_doc]/[1]\"\r\n  },\r\n  \"status\": 404\r\n}\r\n```","created_at":"2018-09-26T14:04:42Z","updated_at":"2018-10-31T18:10:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"286e8ea83c7d2d2631b07e285c683e071f9e93b1","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":163824881,"node_id":"MDU6TGFiZWwxNjM4MjQ4ODE=","url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Core/Index%20APIs","name":":Core/Index APIs","color":"0e8a16","default":false},{"id":23173,"node_id":"MDU6TGFiZWwyMzE3Mw==","url":"https://api.github.com/repos/elastic/elasticsearch/labels/%3Ebug","name":">bug","color":"b60205","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/34083/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/34083/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/34083/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/04fce0b4d5b0f13f267abe3bb591b9f9f055369c","head":{"label":"cbismuth:33384_raise_resource_not_found_when_no_doc_found","ref":"33384_raise_resource_not_found_when_no_doc_found","sha":"04fce0b4d5b0f13f267abe3bb591b9f9f055369c","user":{"login":"cbismuth","id":21545602,"node_id":"MDQ6VXNlcjIxNTQ1NjAy","avatar_url":"https://avatars1.githubusercontent.com/u/21545602?v=4","gravatar_id":"","url":"https://api.github.com/users/cbismuth","html_url":"https://github.com/cbismuth","followers_url":"https://api.github.com/users/cbismuth/followers","following_url":"https://api.github.com/users/cbismuth/following{/other_user}","gists_url":"https://api.github.com/users/cbismuth/gists{/gist_id}","starred_url":"https://api.github.com/users/cbismuth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbismuth/subscriptions","organizations_url":"https://api.github.com/users/cbismuth/orgs","repos_url":"https://api.github.com/users/cbismuth/repos","events_url":"https://api.github.com/users/cbismuth/events{/privacy}","received_events_url":"https://api.github.com/users/cbismuth/received_events","type":"User","site_admin":false},"repo":{"id":148168715,"node_id":"MDEwOlJlcG9zaXRvcnkxNDgxNjg3MTU=","name":"elasticsearch","full_name":"cbismuth/elasticsearch","private":false,"owner":{"login":"cbismuth","id":21545602,"node_id":"MDQ6VXNlcjIxNTQ1NjAy","avatar_url":"https://avatars1.githubusercontent.com/u/21545602?v=4","gravatar_id":"","url":"https://api.github.com/users/cbismuth","html_url":"https://github.com/cbismuth","followers_url":"https://api.github.com/users/cbismuth/followers","following_url":"https://api.github.com/users/cbismuth/following{/other_user}","gists_url":"https://api.github.com/users/cbismuth/gists{/gist_id}","starred_url":"https://api.github.com/users/cbismuth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbismuth/subscriptions","organizations_url":"https://api.github.com/users/cbismuth/orgs","repos_url":"https://api.github.com/users/cbismuth/repos","events_url":"https://api.github.com/users/cbismuth/events{/privacy}","received_events_url":"https://api.github.com/users/cbismuth/received_events","type":"User","site_admin":false},"html_url":"https://github.com/cbismuth/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/cbismuth/elasticsearch","forks_url":"https://api.github.com/repos/cbismuth/elasticsearch/forks","keys_url":"https://api.github.com/repos/cbismuth/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cbismuth/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cbismuth/elasticsearch/teams","hooks_url":"https://api.github.com/repos/cbismuth/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/cbismuth/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/cbismuth/elasticsearch/events","assignees_url":"https://api.github.com/repos/cbismuth/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/cbismuth/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/cbismuth/elasticsearch/tags","blobs_url":"https://api.github.com/repos/cbismuth/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cbismuth/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cbismuth/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/cbismuth/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cbismuth/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/cbismuth/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/cbismuth/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/cbismuth/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/cbismuth/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/cbismuth/elasticsearch/subscription","commits_url":"https://api.github.com/repos/cbismuth/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/cbismuth/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/cbismuth/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/cbismuth/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/cbismuth/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/cbismuth/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cbismuth/elasticsearch/merges","archive_url":"https://api.github.com/repos/cbismuth/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cbismuth/elasticsearch/downloads","issues_url":"https://api.github.com/repos/cbismuth/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/cbismuth/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/cbismuth/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/cbismuth/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cbismuth/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/cbismuth/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/cbismuth/elasticsearch/deployments","created_at":"2018-09-10T14:32:38Z","updated_at":"2018-10-31T13:02:22Z","pushed_at":"2018-10-31T17:37:14Z","git_url":"git://github.com/cbismuth/elasticsearch.git","ssh_url":"git@github.com:cbismuth/elasticsearch.git","clone_url":"https://github.com/cbismuth/elasticsearch.git","svn_url":"https://github.com/cbismuth/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":519874,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"bdd84609063b69e5da5f3e2dbdb1c31a451122da","user":{"login":"elastic","id":6764390,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY3NjQzOTA=","avatar_url":"https://avatars0.githubusercontent.com/u/6764390?v=4","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":507775,"node_id":"MDEwOlJlcG9zaXRvcnk1MDc3NzU=","name":"elasticsearch","full_name":"elastic/elasticsearch","private":false,"owner":{"login":"elastic","id":6764390,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY3NjQzOTA=","avatar_url":"https://avatars0.githubusercontent.com/u/6764390?v=4","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/elastic/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":false,"url":"https://api.github.com/repos/elastic/elasticsearch","forks_url":"https://api.github.com/repos/elastic/elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/elasticsearch/releases{/id}","deployments_url":"https://api.github.com/repos/elastic/elasticsearch/deployments","created_at":"2010-02-08T13:20:56Z","updated_at":"2018-10-31T18:06:23Z","pushed_at":"2018-10-31T18:05:58Z","git_url":"git://github.com/elastic/elasticsearch.git","ssh_url":"git@github.com:elastic/elasticsearch.git","clone_url":"https://github.com/elastic/elasticsearch.git","svn_url":"https://github.com/elastic/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":526562,"stargazers_count":35700,"watchers_count":35700,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":12043,"mirror_url":null,"archived":false,"open_issues_count":1738,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":12043,"open_issues":1738,"watchers":35700,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/34083"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/34083"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/34083"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/34083/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/34083/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/34083/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/04fce0b4d5b0f13f267abe3bb591b9f9f055369c"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"nik9000"}}