Propogate version in reindex from remote search (#42958)
This is related to #31908. In order to use the external version in a reindex from remote request, the search request must be configured to request the version (as it is not returned by default). This commit modifies the search request to request the version. Additionally, it modifies our current reindex from remote tests to randomly use the external version_type.
This commit is contained in:
parent
ca5dbf93a5
commit
d18f511327
|
@ -77,7 +77,7 @@ forbiddenPatterns {
|
|||
exclude '**/*.p12'
|
||||
}
|
||||
|
||||
// Support for testing reindex-from-remote against old Elaticsearch versions
|
||||
// Support for testing reindex-from-remote against old Elasticsearch versions
|
||||
configurations {
|
||||
oldesFixture
|
||||
es2
|
||||
|
|
|
@ -84,14 +84,13 @@ final class RemoteRequestBuilders {
|
|||
request.addParameter("scroll", keepAlive.getStringRep());
|
||||
}
|
||||
request.addParameter("size", Integer.toString(searchRequest.source().size()));
|
||||
if (searchRequest.source().version() == null || searchRequest.source().version() == true) {
|
||||
/*
|
||||
* Passing `null` here just add the `version` request parameter
|
||||
* without any value. This way of requesting the version works
|
||||
* for all supported versions of Elasticsearch.
|
||||
*/
|
||||
request.addParameter("version", null);
|
||||
|
||||
if (searchRequest.source().version() == null || searchRequest.source().version() == false) {
|
||||
request.addParameter("version", Boolean.FALSE.toString());
|
||||
} else {
|
||||
request.addParameter("version", Boolean.TRUE.toString());
|
||||
}
|
||||
|
||||
if (searchRequest.source().sorts() != null) {
|
||||
boolean useScan = false;
|
||||
// Detect if we should use search_type=scan rather than a sort
|
||||
|
|
|
@ -73,6 +73,7 @@ public class ManyDocumentsIT extends ESRestTestCase {
|
|||
Map<?, ?> http = (Map<?, ?>) nodeInfo.get("http");
|
||||
String remote = "http://"+ http.get("publish_address");
|
||||
Request request = new Request("POST", "/_reindex");
|
||||
if (randomBoolean()) {
|
||||
request.setJsonEntity(
|
||||
"{\n" +
|
||||
" \"source\":{\n" +
|
||||
|
@ -85,6 +86,22 @@ public class ManyDocumentsIT extends ESRestTestCase {
|
|||
" \"index\":\"des\"\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
} else {
|
||||
// Test with external version_type
|
||||
request.setJsonEntity(
|
||||
"{\n" +
|
||||
" \"source\":{\n" +
|
||||
" \"index\":\"test\",\n" +
|
||||
" \"remote\":{\n" +
|
||||
" \"host\":\"" + remote + "\"\n" +
|
||||
" }\n" +
|
||||
" }\n," +
|
||||
" \"dest\":{\n" +
|
||||
" \"index\":\"des\",\n" +
|
||||
" \"version_type\": \"external\"\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
}
|
||||
Map<String, Object> response = entityAsMap(client().performRequest(request));
|
||||
assertThat(response, hasEntry("total", count));
|
||||
assertThat(response, hasEntry("created", count));
|
||||
|
|
|
@ -56,6 +56,24 @@ public class ReindexFromOldRemoteIT extends ESRestTestCase {
|
|||
}
|
||||
|
||||
Request reindex = new Request("POST", "/_reindex");
|
||||
if (randomBoolean()) {
|
||||
// Reindex using the external version_type
|
||||
reindex.setJsonEntity(
|
||||
"{\n"
|
||||
+ " \"source\":{\n"
|
||||
+ " \"index\": \"test\",\n"
|
||||
+ " \"size\": 1,\n"
|
||||
+ " \"remote\": {\n"
|
||||
+ " \"host\": \"http://127.0.0.1:" + oldEsPort + "\"\n"
|
||||
+ " }\n"
|
||||
+ " },\n"
|
||||
+ " \"dest\": {\n"
|
||||
+ " \"index\": \"test\",\n"
|
||||
+ " \"version_type\": \"external\"\n"
|
||||
+ " }\n"
|
||||
+ "}");
|
||||
} else {
|
||||
// Reindex using the default internal version_type
|
||||
reindex.setJsonEntity(
|
||||
"{\n"
|
||||
+ " \"source\":{\n"
|
||||
|
@ -69,6 +87,7 @@ public class ReindexFromOldRemoteIT extends ESRestTestCase {
|
|||
+ " \"index\": \"test\"\n"
|
||||
+ " }\n"
|
||||
+ "}");
|
||||
}
|
||||
reindex.addParameter("refresh", "true");
|
||||
reindex.addParameter("pretty", "true");
|
||||
if (requestsPerSecond != null) {
|
||||
|
|
|
@ -198,7 +198,12 @@ public class RemoteRequestBuildersTests extends ESTestCase {
|
|||
assertScroll(remoteVersion, params, scroll);
|
||||
}
|
||||
assertThat(params, hasEntry("size", Integer.toString(size)));
|
||||
assertThat(params, fetchVersion == null || fetchVersion == true ? hasEntry("version", null) : not(hasEntry("version", null)));
|
||||
if (fetchVersion != null) {
|
||||
assertThat(params, fetchVersion ? hasEntry("version", Boolean.TRUE.toString()) :
|
||||
hasEntry("version", Boolean.FALSE.toString()));
|
||||
} else {
|
||||
assertThat(params, hasEntry("version", Boolean.FALSE.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private void assertScroll(Version remoteVersion, Map<String, String> params, TimeValue requested) {
|
||||
|
|
Loading…
Reference in New Issue