From 4063354dbe6d08263fd759af59170121ccafd991 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Tue, 10 Nov 2015 17:19:05 +0100 Subject: [PATCH] Fix Delete-by-Query with Shield closes #14527 --- .../action/bulk/BulkRequest.java | 11 +++++++ .../action/search/ClearScrollRequest.java | 11 +++++++ .../action/search/SearchScrollRequest.java | 8 +++++ .../TransportDeleteByQueryAction.java | 33 +++++++++---------- 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java b/core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java index fa6b643eb69..260fd5e732d 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/BulkRequest.java @@ -64,6 +64,17 @@ public class BulkRequest extends ActionRequest implements Composite private long sizeInBytes = 0; + public BulkRequest() { + } + + /** + * Creates a bulk request caused by some other request, which is provided as an + * argument so that its headers and context can be copied to the new request + */ + public BulkRequest(ActionRequest request) { + super(request); + } + /** * Adds a list of requests to be executed. Either index or delete requests. */ diff --git a/core/src/main/java/org/elasticsearch/action/search/ClearScrollRequest.java b/core/src/main/java/org/elasticsearch/action/search/ClearScrollRequest.java index 17343e86912..b390b77504a 100644 --- a/core/src/main/java/org/elasticsearch/action/search/ClearScrollRequest.java +++ b/core/src/main/java/org/elasticsearch/action/search/ClearScrollRequest.java @@ -37,6 +37,17 @@ public class ClearScrollRequest extends ActionRequest { private List scrollIds; + public ClearScrollRequest() { + } + + /** + * Creates a clear scroll request caused by some other request, which is provided as an + * argument so that its headers and context can be copied to the new request + */ + public ClearScrollRequest(ActionRequest request) { + super(request); + } + public List getScrollIds() { return scrollIds; } diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchScrollRequest.java b/core/src/main/java/org/elasticsearch/action/search/SearchScrollRequest.java index c1ff788dae5..537d61ac558 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchScrollRequest.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchScrollRequest.java @@ -46,6 +46,14 @@ public class SearchScrollRequest extends ActionRequest { this.scrollId = scrollId; } + /** + * Creates a scroll request caused by some other request, which is provided as an + * argument so that its headers and context can be copied to the new request + */ + public SearchScrollRequest(ActionRequest request) { + super(request); + } + @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; diff --git a/plugins/delete-by-query/src/main/java/org/elasticsearch/action/deletebyquery/TransportDeleteByQueryAction.java b/plugins/delete-by-query/src/main/java/org/elasticsearch/action/deletebyquery/TransportDeleteByQueryAction.java index 83a30156ee7..df57aca1668 100644 --- a/plugins/delete-by-query/src/main/java/org/elasticsearch/action/deletebyquery/TransportDeleteByQueryAction.java +++ b/plugins/delete-by-query/src/main/java/org/elasticsearch/action/deletebyquery/TransportDeleteByQueryAction.java @@ -27,13 +27,7 @@ import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteResponse; -import org.elasticsearch.action.search.ClearScrollResponse; -import org.elasticsearch.action.search.SearchRequest; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchScrollRequest; -import org.elasticsearch.action.search.ShardSearchFailure; -import org.elasticsearch.action.search.TransportSearchAction; -import org.elasticsearch.action.search.TransportSearchScrollAction; +import org.elasticsearch.action.search.*; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.HandledTransportAction; import org.elasticsearch.client.Client; @@ -48,10 +42,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; @@ -109,8 +100,11 @@ public class TransportDeleteByQueryAction extends HandledTransportAction() { + scrollAction.execute(new SearchScrollRequest(request).scrollId(scrollId).scroll(request.scroll()), new ActionListener() { @Override public void onResponse(SearchResponse scrollResponse) { deleteHits(scrollId, scrollResponse); @@ -197,9 +192,9 @@ public class TransportDeleteByQueryAction extends HandledTransportAction() { + ClearScrollRequest clearScrollRequest = new ClearScrollRequest(request); + clearScrollRequest.addScrollId(scrollId); + client.clearScroll(clearScrollRequest, new ActionListener() { @Override public void onResponse(ClearScrollResponse clearScrollResponse) { logger.trace("scroll id [{}] cleared", scrollId);