HLRC: Fix Reindex from remote query logic (#36908)

The query object was incorrectly added to the remote object in the
xcontent. This fix moves the query back into the source, if it was
passed in as part of the RemoteInfo. It also adds a IPv6 test for
reindex from remote such that we can properly validate this.
This commit is contained in:
Michael Basnight 2019-01-04 13:37:59 -06:00 committed by GitHub
parent e38cf1d0dc
commit e40193ae66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 10 deletions

View File

@ -103,6 +103,7 @@ integTestRunner {
integTestCluster { integTestCluster {
systemProperty 'es.scripting.update.ctx_in_params', 'false' systemProperty 'es.scripting.update.ctx_in_params', 'false'
setting 'reindex.remote.whitelist', '"[::1]:*"'
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'true' setting 'xpack.security.enabled', 'true'
setting 'xpack.security.authc.token.enabled', 'true' setting 'xpack.security.authc.token.enabled', 'true'

View File

@ -19,6 +19,7 @@
package org.elasticsearch.client.documentation; package org.elasticsearch.client.documentation;
import org.apache.http.HttpHost;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.DocWriteRequest; import org.elasticsearch.action.DocWriteRequest;
@ -823,9 +824,6 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
// tag::reindex-request-conflicts // tag::reindex-request-conflicts
request.setConflicts("proceed"); // <1> request.setConflicts("proceed"); // <1>
// end::reindex-request-conflicts // end::reindex-request-conflicts
// tag::reindex-request-query
request.setSourceQuery(new TermQueryBuilder("user", "kimchy")); // <1>
// end::reindex-request-query
// tag::reindex-request-size // tag::reindex-request-size
request.setSize(10); // <1> request.setSize(10); // <1>
// end::reindex-request-size // end::reindex-request-size
@ -846,27 +844,29 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
"if (ctx._source.user == 'kimchy') {ctx._source.likes++;}", "if (ctx._source.user == 'kimchy') {ctx._source.likes++;}",
Collections.emptyMap())); // <1> Collections.emptyMap())); // <1>
// end::reindex-request-script // end::reindex-request-script
HttpHost host = getClusterHosts().get(0);
Integer remotePort = host.getPort();
String remoteHost = host.getHostName();
String user = "test_user";
String password = "test-password";
// tag::reindex-request-remote // tag::reindex-request-remote
request.setRemoteInfo( request.setRemoteInfo(
new RemoteInfo( new RemoteInfo(
"https", "localhost", 9002, null, "http", remoteHost, remotePort, null,
new BytesArray(new MatchAllQueryBuilder().toString()), new BytesArray(new MatchAllQueryBuilder().toString()),
"user", "pass", Collections.emptyMap(), user, password, Collections.emptyMap(),
new TimeValue(100, TimeUnit.MILLISECONDS), new TimeValue(100, TimeUnit.MILLISECONDS),
new TimeValue(100, TimeUnit.SECONDS) new TimeValue(100, TimeUnit.SECONDS)
) )
); // <1> ); // <1>
// end::reindex-request-remote // end::reindex-request-remote
request.setRemoteInfo(null); // Remove it for tests
// tag::reindex-request-timeout // tag::reindex-request-timeout
request.setTimeout(TimeValue.timeValueMinutes(2)); // <1> request.setTimeout(TimeValue.timeValueMinutes(2)); // <1>
// end::reindex-request-timeout // end::reindex-request-timeout
// tag::reindex-request-refresh // tag::reindex-request-refresh
request.setRefresh(true); // <1> request.setRefresh(true); // <1>
// end::reindex-request-refresh // end::reindex-request-refresh
// tag::reindex-request-slices
request.setSlices(2); // <1>
// end::reindex-request-slices
// tag::reindex-request-scroll // tag::reindex-request-scroll
request.setScroll(TimeValue.timeValueMinutes(10)); // <1> request.setScroll(TimeValue.timeValueMinutes(10)); // <1>
// end::reindex-request-scroll // end::reindex-request-scroll
@ -904,6 +904,14 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
request.setSourceIndices("source1"); request.setSourceIndices("source1");
request.setDestIndex("dest"); request.setDestIndex("dest");
// These cannot be set with a remote set, so its set here instead for the docs
// tag::reindex-request-query
request.setSourceQuery(new TermQueryBuilder("user", "kimchy")); // <1>
// end::reindex-request-query
// tag::reindex-request-slices
request.setSlices(2); // <1>
// end::reindex-request-slices
ActionListener<BulkByScrollResponse> listener; ActionListener<BulkByScrollResponse> listener;
// tag::reindex-execute-listener // tag::reindex-execute-listener
listener = new ActionListener<BulkByScrollResponse>() { listener = new ActionListener<BulkByScrollResponse>() {

View File

@ -293,6 +293,7 @@ public class ReindexRequest extends AbstractBulkIndexByScrollRequest<ReindexRequ
builder.startObject("source"); builder.startObject("source");
if (remoteInfo != null) { if (remoteInfo != null) {
builder.field("remote", remoteInfo); builder.field("remote", remoteInfo);
builder.rawField("query", remoteInfo.getQuery().streamInput(), builder.contentType());
} }
builder.array("index", getSearchRequest().indices()); builder.array("index", getSearchRequest().indices());
String[] types = getSearchRequest().types(); String[] types = getSearchRequest().types();

View File

@ -209,7 +209,6 @@ public class RemoteInfo implements Writeable, ToXContentObject {
} }
builder.field("socket_timeout", socketTimeout.getStringRep()); builder.field("socket_timeout", socketTimeout.getStringRep());
builder.field("connect_timeout", connectTimeout.getStringRep()); builder.field("connect_timeout", connectTimeout.getStringRep());
builder.field("query", query);
builder.endObject(); builder.endObject();
return builder; return builder;
} }