Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/reindex/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ apply plugin: 'elasticsearch.test-with-dependencies'
apply plugin: 'elasticsearch.jdk-download'
apply plugin: 'elasticsearch.yaml-rest-test'
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'
apply plugin: 'elasticsearch.internal-cluster-test'

esplugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ protected ReindexRequest buildRequest(RestRequest request, NamedWriteableRegistr

ReindexRequest internal;
try (XContentParser parser = request.contentParser()) {
internal = ReindexRequest.fromXContent(parser);
if (parser.useCompatibility()) {
internal = ReindexRequestV7.fromXContentV7(parser);
} else {
internal = ReindexRequest.fromXContent(parser);
}
}

if (request.hasParam("scroll")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public static ReindexRequest fromXContent(XContentParser parser) throws IOExcept
* Yank a string array from a map. Emulates XContent's permissive String to
* String array conversions and allow comma separated String.
*/
private static String[] extractStringArray(Map<String, Object> source, String name) {
static String[] extractStringArray(Map<String, Object> source, String name) {
Object value = source.remove(name);
if (value == null) {
return null;
Expand Down Expand Up @@ -465,7 +465,7 @@ static void setMaxDocsValidateIdentical(AbstractBulkByScrollRequest<?> request,
}
}

private static void failOnSizeSpecified() {
static void failOnSizeSpecified() {
throw new IllegalArgumentException("invalid parameter [size], use [max_docs] instead");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.index.reindex;

import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.VersionType;
import org.elasticsearch.script.Script;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

/**
* A V7 version of ReindexRequest parser
*/
public class ReindexRequestV7 {

static final ObjectParser<ReindexRequest, Void> PARSER = new ObjectParser<>("reindex_v7");

static {
ObjectParser.Parser<ReindexRequest, Void> sourceParser = (parser, request, context) -> {
// Funky hack to work around Search not having a proper ObjectParser and us wanting to extract query if using remote.
Map<String, Object> source = parser.map();
String[] indices = ReindexRequest.extractStringArray(source, "index");
if (indices != null) {
request.getSearchRequest().indices(indices);
}
request.setRemoteInfo(ReindexRequest.buildRemoteInfo(source));
XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType());
builder.map(source);
try (InputStream stream = BytesReference.bytes(builder).streamInput();
XContentParser innerParser = parser.contentType().xContent()
.createParser(parser.getXContentRegistry(), parser.getDeprecationHandler(), stream)) {
request.getSearchRequest().source().parseXContent(innerParser, false);
}
};

ObjectParser<IndexRequest, Void> destParser = new ObjectParser<>("dest");
destParser.declareString(IndexRequest::index, new ParseField("index"));
destParser.declareString(IndexRequest::routing, new ParseField("routing"));
destParser.declareString(IndexRequest::opType, new ParseField("op_type"));
destParser.declareString(IndexRequest::setPipeline, new ParseField("pipeline"));
destParser.declareString((s, i) -> s.versionType(VersionType.fromString(i)), new ParseField("version_type"));

PARSER.declareField(sourceParser::parse, new ParseField("source"), ObjectParser.ValueType.OBJECT);
PARSER.declareField((p, v, c) -> destParser.parse(p, v.getDestination(), c), new ParseField("dest"), ObjectParser.ValueType.OBJECT);

PARSER.declareInt(ReindexRequest::setMaxDocsValidateIdentical, new ParseField("max_docs", "size"));

PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p)), new ParseField("script"),
ObjectParser.ValueType.OBJECT);
PARSER.declareString(ReindexRequest::setConflicts, new ParseField("conflicts"));
}

public static ReindexRequest fromXContentV7(XContentParser parser) throws IOException {
ReindexRequest reindexRequest = new ReindexRequest();
PARSER.parse(parser, reindexRequest, null);
return reindexRequest;
}


}