{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/45583073","id":45583073,"diff_hunk":"@@ -137,4 +142,106 @@ public void failed(Exception e) {\n     public int order() {\n         return Integer.MAX_VALUE;\n     }\n+\n+    final static class BulkProcessingState implements Iterator<ActionRequest> {\n+\n+        final String action;\n+        final String pipelineId;\n+        final ActionFilterChain chain;\n+        final BulkRequest bulkRequest;\n+        final ActionListener<BulkResponse> listener;\n+\n+        final Set<Integer> failedSlots;\n+        final List<BulkItemResponse> itemResponses;\n+\n+        int currentSlot = -1;\n+\n+        BulkProcessingState(String action, String pipelineId, ActionFilterChain chain, BulkRequest bulkRequest,\n+                            ActionListener<BulkResponse> listener) {\n+            this.action = action;\n+            this.pipelineId = pipelineId;\n+            this.chain = chain;\n+            this.bulkRequest = bulkRequest;\n+            this.listener = listener;\n+            this.failedSlots = new HashSet<>();\n+            this.itemResponses = new ArrayList<>(bulkRequest.requests().size());\n+        }\n+\n+        @Override\n+        public ActionRequest next() {\n+            return bulkRequest.requests().get(++currentSlot);\n+        }\n+\n+        @Override\n+        public boolean hasNext() {\n+            return (currentSlot + 1) < bulkRequest.requests().size();\n+        }\n+\n+        void proceed() {\n+            if (itemResponses.isEmpty()) {\n+                chain.proceed(action, bulkRequest, listener);\n+            } else {\n+                BulkRequest modifiedBulkRequest = new BulkRequest(bulkRequest);\n+                modifiedBulkRequest.refresh(bulkRequest.refresh());\n+                modifiedBulkRequest.consistencyLevel(bulkRequest.consistencyLevel());\n+                modifiedBulkRequest.timeout(bulkRequest.timeout());\n+\n+                List<Integer> originalSlots = new ArrayList<>();\n+                for (int i = 0; i < bulkRequest.requests().size(); i++) {\n+                    ActionRequest request = bulkRequest.requests().get(i);\n+                    if (failedSlots.contains(i) == false) {\n+                        originalSlots.add(i);\n+                        modifiedBulkRequest.add(request);\n+                    }\n+                }\n+\n+                if (modifiedBulkRequest.requests().isEmpty()) {\n+                    // in this stage, the transport bulk action can't deal with a bulk request with no requests,\n+                    // so we stop and send a empty response back to the client.\n+                    // (this will happen if all preprocessing all items in the bulk failed)\n+                    listener.onResponse(new BulkResponse(itemResponses.toArray(new BulkItemResponse[0]), 0));","path":"plugins/ingest/src/main/java/org/elasticsearch/plugin/ingest/transport/IngestActionFilter.java","position":141,"original_position":141,"commit_id":"6f40576745d1a4d7a85c12d1f78968d550e835f9","original_commit_id":"6f40576745d1a4d7a85c12d1f78968d550e835f9","user":{"login":"martijnvg","id":580421,"avatar_url":"https://avatars.githubusercontent.com/u/580421?v=3","gravatar_id":"","url":"https://api.github.com/users/martijnvg","html_url":"https://github.com/martijnvg","followers_url":"https://api.github.com/users/martijnvg/followers","following_url":"https://api.github.com/users/martijnvg/following{/other_user}","gists_url":"https://api.github.com/users/martijnvg/gists{/gist_id}","starred_url":"https://api.github.com/users/martijnvg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martijnvg/subscriptions","organizations_url":"https://api.github.com/users/martijnvg/orgs","repos_url":"https://api.github.com/users/martijnvg/repos","events_url":"https://api.github.com/users/martijnvg/events{/privacy}","received_events_url":"https://api.github.com/users/martijnvg/received_events","type":"User","site_admin":false},"body":"I replaced it with an empty array","created_at":"2015-11-23T09:21:51Z","updated_at":"2015-11-23T09:21:51Z","html_url":"https://github.com/elastic/elasticsearch/pull/14888#discussion_r45583073","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/14888","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/45583073"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/14888#discussion_r45583073"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/14888"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/14888","id":51359515,"html_url":"https://github.com/elastic/elasticsearch/pull/14888","diff_url":"https://github.com/elastic/elasticsearch/pull/14888.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/14888.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/14888","number":14888,"state":"open","locked":false,"title":"[Ingest] Ingest better bulk failure handling","user":{"login":"martijnvg","id":580421,"avatar_url":"https://avatars.githubusercontent.com/u/580421?v=3","gravatar_id":"","url":"https://api.github.com/users/martijnvg","html_url":"https://github.com/martijnvg","followers_url":"https://api.github.com/users/martijnvg/followers","following_url":"https://api.github.com/users/martijnvg/following{/other_user}","gists_url":"https://api.github.com/users/martijnvg/gists{/gist_id}","starred_url":"https://api.github.com/users/martijnvg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martijnvg/subscriptions","organizations_url":"https://api.github.com/users/martijnvg/orgs","repos_url":"https://api.github.com/users/martijnvg/repos","events_url":"https://api.github.com/users/martijnvg/events{/privacy}","received_events_url":"https://api.github.com/users/martijnvg/received_events","type":"User","site_admin":false},"body":"With this change if ingest pipeline fails only the index request in the bulk fails whereas right now the entire bulk request is failed.\r\n\r\nIf pipeline processing fails then the index request gets reported as a failure in the bulk response in its respective place. The index request will not be executed after pipeline processing has been completed.\r\n\r\nIf pipeline failures occur a new bulk request will be created based on the current bulk request. Only index requests that have successfully been processed by the pipeline will be included in this new bulk request. Then when sending back the bulk response the new bulk request will map its response items in such a way that the order of all items and errors is the same and matches with the original bulk request that was sent.","created_at":"2015-11-20T14:02:58Z","updated_at":"2015-11-23T09:21:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4c297aa814fd294f1652d8fe0adede3657d0b079","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/14888/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/14888/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/14888/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/6f40576745d1a4d7a85c12d1f78968d550e835f9","head":{"label":"martijnvg:ingest_better_bulk_failure_handeling","ref":"ingest_better_bulk_failure_handeling","sha":"6f40576745d1a4d7a85c12d1f78968d550e835f9","user":{"login":"martijnvg","id":580421,"avatar_url":"https://avatars.githubusercontent.com/u/580421?v=3","gravatar_id":"","url":"https://api.github.com/users/martijnvg","html_url":"https://github.com/martijnvg","followers_url":"https://api.github.com/users/martijnvg/followers","following_url":"https://api.github.com/users/martijnvg/following{/other_user}","gists_url":"https://api.github.com/users/martijnvg/gists{/gist_id}","starred_url":"https://api.github.com/users/martijnvg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martijnvg/subscriptions","organizations_url":"https://api.github.com/users/martijnvg/orgs","repos_url":"https://api.github.com/users/martijnvg/repos","events_url":"https://api.github.com/users/martijnvg/events{/privacy}","received_events_url":"https://api.github.com/users/martijnvg/received_events","type":"User","site_admin":false},"repo":{"id":3584739,"name":"elasticsearch","full_name":"martijnvg/elasticsearch","owner":{"login":"martijnvg","id":580421,"avatar_url":"https://avatars.githubusercontent.com/u/580421?v=3","gravatar_id":"","url":"https://api.github.com/users/martijnvg","html_url":"https://github.com/martijnvg","followers_url":"https://api.github.com/users/martijnvg/followers","following_url":"https://api.github.com/users/martijnvg/following{/other_user}","gists_url":"https://api.github.com/users/martijnvg/gists{/gist_id}","starred_url":"https://api.github.com/users/martijnvg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martijnvg/subscriptions","organizations_url":"https://api.github.com/users/martijnvg/orgs","repos_url":"https://api.github.com/users/martijnvg/repos","events_url":"https://api.github.com/users/martijnvg/events{/privacy}","received_events_url":"https://api.github.com/users/martijnvg/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/martijnvg/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine with grouping","fork":true,"url":"https://api.github.com/repos/martijnvg/elasticsearch","forks_url":"https://api.github.com/repos/martijnvg/elasticsearch/forks","keys_url":"https://api.github.com/repos/martijnvg/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/martijnvg/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/martijnvg/elasticsearch/teams","hooks_url":"https://api.github.com/repos/martijnvg/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/martijnvg/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/martijnvg/elasticsearch/events","assignees_url":"https://api.github.com/repos/martijnvg/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/martijnvg/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/martijnvg/elasticsearch/tags","blobs_url":"https://api.github.com/repos/martijnvg/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/martijnvg/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/martijnvg/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/martijnvg/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/martijnvg/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/martijnvg/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/martijnvg/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/martijnvg/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/martijnvg/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/martijnvg/elasticsearch/subscription","commits_url":"https://api.github.com/repos/martijnvg/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/martijnvg/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/martijnvg/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/martijnvg/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/martijnvg/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/martijnvg/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/martijnvg/elasticsearch/merges","archive_url":"https://api.github.com/repos/martijnvg/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/martijnvg/elasticsearch/downloads","issues_url":"https://api.github.com/repos/martijnvg/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/martijnvg/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/martijnvg/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/martijnvg/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/martijnvg/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/martijnvg/elasticsearch/releases{/id}","created_at":"2012-02-29T18:56:33Z","updated_at":"2014-08-09T22:19:31Z","pushed_at":"2015-11-23T08:47:28Z","git_url":"git://github.com/martijnvg/elasticsearch.git","ssh_url":"git@github.com:martijnvg/elasticsearch.git","clone_url":"https://github.com/martijnvg/elasticsearch.git","svn_url":"https://github.com/martijnvg/elasticsearch","homepage":"http://elasticsearch.org","size":169739,"stargazers_count":12,"watchers_count":12,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":0,"forks":2,"open_issues":0,"watchers":12,"default_branch":"master"}},"base":{"label":"elastic:feature/ingest","ref":"feature/ingest","sha":"404ae395ca6e916e480aa330082448cee4015c0f","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","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,"name":"elasticsearch","full_name":"elastic/elasticsearch","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","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},"private":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}","created_at":"2010-02-08T13:20:56Z","updated_at":"2015-11-23T09:12:56Z","pushed_at":"2015-11-23T09:09:29Z","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":222144,"stargazers_count":13660,"watchers_count":13660,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4515,"mirror_url":null,"open_issues_count":1212,"forks":4515,"open_issues":1212,"watchers":13660,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/14888"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/14888"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/14888"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/14888/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/14888/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/14888/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/6f40576745d1a4d7a85c12d1f78968d550e835f9"}}}}