Bläddra i källkod

Reindex from Remote encoding (#41007)

Removed the leniency when encoding remote reindex search requests that
was introduced in 7.x. All index-names are now encoded before being sent
to the remote host.

Follow-up to #40303
Henning Andersen 6 år sedan
förälder
incheckning
8dbdd06886

+ 2 - 0
docs/reference/migration/migrate_8_0.asciidoc

@@ -22,6 +22,7 @@ coming[8.0.0]
 * <<breaking_80_network_changes>>
 * <<breaking_80_transport_changes>>
 * <<breaking_80_http_changes>>
+* <<breaking_80_reindex_changes>>
 
 //NOTE: The notable-breaking-changes tagged regions are re-used in the
 //Installation and Upgrade Guide
@@ -55,3 +56,4 @@ include::migrate_8_0/java.asciidoc[]
 include::migrate_8_0/network.asciidoc[]
 include::migrate_8_0/transport.asciidoc[]
 include::migrate_8_0/http.asciidoc[]
+include::migrate_8_0/reindex.asciidoc[]

+ 10 - 0
docs/reference/migration/migrate_8_0/reindex.asciidoc

@@ -0,0 +1,10 @@
+[float]
+[[breaking_80_reindex_changes]]
+=== Reindex changes
+
+Reindex from remote would previously allow URL encoded index-names and not
+re-encode them when generating the search request for the remote host. This
+leniency has been removed such that all index-names are correctly encoded when
+reindex generates remote search requests.
+
+Instead, please specify the index-name without any encoding.

+ 0 - 4
modules/reindex/src/main/java/org/elasticsearch/index/reindex/remote/RemoteRequestBuilders.java

@@ -171,10 +171,6 @@ final class RemoteRequestBuilders {
     }
 
     private static String encodeIndex(String s) {
-        if (s.contains("%")) { // already encoded, pass-through to allow this in mixed version clusters
-            checkIndexOrType("Index", s);
-            return s;
-        }
         try {
             return URLEncoder.encode(s, "utf-8");
         } catch (UnsupportedEncodingException e) {

+ 4 - 6
modules/reindex/src/test/java/org/elasticsearch/index/reindex/remote/RemoteRequestBuildersTests.java

@@ -79,15 +79,13 @@ public class RemoteRequestBuildersTests extends ESTestCase {
         assertEquals("/%3Ccat%7Bnow%2Fd%7D%3E,%3C%3E%2F%7B%7D%7C%2B%3A%2C/c,d/_search",
             initialSearch(searchRequest, query, remoteVersion).getEndpoint());
 
-        // pass-through if already escaped.
+        // re-escape already escaped (no special handling).
         searchRequest.indices("%2f", "%3a");
-        assertEquals("/%2f,%3a/c,d/_search", initialSearch(searchRequest, query, remoteVersion).getEndpoint());
-
-        // do not allow , and / if already escaped.
+        assertEquals("/%252f,%253a/c,d/_search", initialSearch(searchRequest, query, remoteVersion).getEndpoint());
         searchRequest.indices("%2fcat,");
-        expectBadStartRequest(searchRequest, "Index", ",", "%2fcat,");
+        assertEquals("/%252fcat%2C/c,d/_search", initialSearch(searchRequest, query, remoteVersion).getEndpoint());
         searchRequest.indices("%3ccat/");
-        expectBadStartRequest(searchRequest, "Index", "/", "%3ccat/");
+        assertEquals("/%253ccat%2F/c,d/_search", initialSearch(searchRequest, query, remoteVersion).getEndpoint());
 
         searchRequest.indices("ok");
         searchRequest.types("cat,");