From d587a745331555f941d73b38cc62b32fd26f7ba4 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 29 Feb 2016 10:04:16 -0500 Subject: [PATCH] Fix reindex to work with master branch Stuff changed, reindex's got to change. --- .../action/index/IndexRequest.java | 7 ++++ .../AbstractBaseReindexRestHandler.java | 5 ++- .../index/reindex/RestReindexAction.java | 29 +++++++++---- .../reindex/RestUpdateByQueryAction.java | 7 ++-- .../index/reindex/TransportReindexAction.java | 42 +++++++++++++------ 5 files changed, 66 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java b/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java index 1b15b8b0b99..94614fb01d9 100644 --- a/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java +++ b/core/src/main/java/org/elasticsearch/action/index/IndexRequest.java @@ -223,6 +223,13 @@ public class IndexRequest extends ReplicationRequest implements Do return validationException; } + /** + * The content type that will be used when generating a document from user provided objects like Maps. + */ + public XContentType getContentType() { + return contentType; + } + /** * Sets the content type that will be used when generating a document from user provided objects (like Map). */ diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java index 846fedbfb1c..6f50b216c9b 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractBaseReindexRestHandler.java @@ -32,6 +32,7 @@ import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.tasks.LoggingTaskListener; import org.elasticsearch.tasks.Task; @@ -40,13 +41,15 @@ import java.io.IOException; public abstract class AbstractBaseReindexRestHandler, Response extends BulkIndexByScrollResponse, TA extends TransportAction> extends BaseRestHandler { protected final IndicesQueriesRegistry indicesQueriesRegistry; + protected final AggregatorParsers aggParsers; private final ClusterService clusterService; private final TA action; protected AbstractBaseReindexRestHandler(Settings settings, Client client, - IndicesQueriesRegistry indicesQueriesRegistry, ClusterService clusterService, TA action) { + IndicesQueriesRegistry indicesQueriesRegistry, AggregatorParsers aggParsers, ClusterService clusterService, TA action) { super(settings, client); this.indicesQueriesRegistry = indicesQueriesRegistry; + this.aggParsers = aggParsers; this.clusterService = clusterService; this.action = action; } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java index 4dc40c187a0..c831b176726 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java @@ -42,6 +42,7 @@ import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.script.Script; +import org.elasticsearch.search.aggregations.AggregatorParsers; import java.io.IOException; import java.util.List; @@ -55,9 +56,9 @@ import static org.elasticsearch.rest.RestStatus.BAD_REQUEST; * Expose IndexBySearchRequest over rest. */ public class RestReindexAction extends AbstractBaseReindexRestHandler { - private static final ObjectParser PARSER = new ObjectParser<>("reindex"); + private static final ObjectParser PARSER = new ObjectParser<>("reindex"); static { - ObjectParser.Parser sourceParser = (parser, search, context) -> { + ObjectParser.Parser sourceParser = (parser, search, context) -> { /* * Extract the parameters that we need from the parser. We could do * away with this hack when search source has an ObjectParser. @@ -74,8 +75,8 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler destParser = new ObjectParser<>("dest"); @@ -93,14 +94,16 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler sourceParser.parse(p, v.getSource(), c), new ParseField("source"), ValueType.OBJECT); PARSER.declareField((p, v, c) -> destParser.parse(p, v.getDestination(), null), new ParseField("dest"), ValueType.OBJECT); PARSER.declareInt(ReindexRequest::setSize, new ParseField("size")); - PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p, c.parseFieldMatcher())), new ParseField("script"), ValueType.OBJECT); + PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p, c.queryParseContext.parseFieldMatcher())), new ParseField("script"), + ValueType.OBJECT); PARSER.declareString(ReindexRequest::setConflicts, new ParseField("conflicts")); } @Inject public RestReindexAction(Settings settings, RestController controller, Client client, - IndicesQueriesRegistry indicesQueriesRegistry, ClusterService clusterService, TransportReindexAction action) { - super(settings, client, indicesQueriesRegistry, clusterService, action); + IndicesQueriesRegistry indicesQueriesRegistry, AggregatorParsers aggParsers, ClusterService clusterService, + TransportReindexAction action) { + super(settings, client, indicesQueriesRegistry, aggParsers, clusterService, action); controller.registerHandler(POST, "/_reindex", this); } @@ -114,7 +117,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler { @Inject public RestUpdateByQueryAction(Settings settings, RestController controller, Client client, - IndicesQueriesRegistry indicesQueriesRegistry, ClusterService clusterService, + IndicesQueriesRegistry indicesQueriesRegistry, AggregatorParsers aggParsers, ClusterService clusterService, TransportUpdateByQueryAction action) { - super(settings, client, indicesQueriesRegistry, clusterService, action); + super(settings, client, indicesQueriesRegistry, aggParsers, clusterService, action); controller.registerHandler(POST, "/{index}/_update_by_query", this); controller.registerHandler(POST, "/{index}/{type}/_update_by_query", this); } @@ -95,7 +96,7 @@ public class RestUpdateByQueryAction extends } } RestSearchAction.parseSearchRequest(internalRequest.getSource(), indicesQueriesRegistry, request, - parseFieldMatcher, bodyContent); + parseFieldMatcher, aggParsers, bodyContent); String conflicts = request.param("conflicts"); if (conflicts != null) { diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportReindexAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportReindexAction.java index 746d4cfe4cb..1424b53e07a 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportReindexAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/TransportReindexAction.java @@ -122,26 +122,44 @@ public class TransportReindexAction extends HandledTransportAction