|
@@ -108,7 +108,6 @@ import org.elasticsearch.xcontent.XContentType;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
-import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -238,29 +237,21 @@ public class PainlessExecuteAction {
|
|
return new Tuple<>(null, null);
|
|
return new Tuple<>(null, null);
|
|
}
|
|
}
|
|
String trimmed = indexExpression.trim();
|
|
String trimmed = indexExpression.trim();
|
|
- String sep = String.valueOf(RemoteClusterAware.REMOTE_CLUSTER_INDEX_SEPARATOR);
|
|
|
|
- if (trimmed.startsWith(sep) || trimmed.endsWith(sep)) {
|
|
|
|
- throw new IllegalArgumentException(
|
|
|
|
- "Unable to parse one single valid index name from the provided index: [" + indexExpression + "]"
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ String[] parts = RemoteClusterAware.splitIndexName(trimmed);
|
|
// The parser here needs to ensure that the indexExpression is not of the form "remote1:blogs,remote2:blogs"
|
|
// The parser here needs to ensure that the indexExpression is not of the form "remote1:blogs,remote2:blogs"
|
|
// because (1) only a single index is allowed for Painless Execute and
|
|
// because (1) only a single index is allowed for Painless Execute and
|
|
// (2) if this method returns Tuple("remote1", "blogs,remote2:blogs") that will not fail with "index not found".
|
|
// (2) if this method returns Tuple("remote1", "blogs,remote2:blogs") that will not fail with "index not found".
|
|
// Instead, it will fail with the inaccurate and confusing error message:
|
|
// Instead, it will fail with the inaccurate and confusing error message:
|
|
// "Cross-cluster calls are not supported in this context but remote indices were requested: [blogs,remote1:blogs]"
|
|
// "Cross-cluster calls are not supported in this context but remote indices were requested: [blogs,remote1:blogs]"
|
|
// which comes later out of the IndexNameExpressionResolver pathway this code uses.
|
|
// which comes later out of the IndexNameExpressionResolver pathway this code uses.
|
|
- String[] parts = indexExpression.split(sep, 2);
|
|
|
|
- if (parts.length == 1) {
|
|
|
|
- return new Tuple<>(null, parts[0]);
|
|
|
|
- } else if (parts.length == 2 && parts[1].contains(sep) == false) {
|
|
|
|
- return new Tuple<>(parts[0], parts[1]);
|
|
|
|
- } else {
|
|
|
|
|
|
+ if ((parts[0] != null && parts[1].isEmpty())
|
|
|
|
+ || parts[1].contains(String.valueOf(RemoteClusterAware.REMOTE_CLUSTER_INDEX_SEPARATOR))) {
|
|
throw new IllegalArgumentException(
|
|
throw new IllegalArgumentException(
|
|
"Unable to parse one single valid index name from the provided index: [" + indexExpression + "]"
|
|
"Unable to parse one single valid index name from the provided index: [" + indexExpression + "]"
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return new Tuple<>(parts[0], parts[1]);
|
|
}
|
|
}
|
|
|
|
|
|
public String getClusterAlias() {
|
|
public String getClusterAlias() {
|
|
@@ -556,8 +547,8 @@ public class PainlessExecuteAction {
|
|
// Visible for testing
|
|
// Visible for testing
|
|
static void removeClusterAliasFromIndexExpression(Request request) {
|
|
static void removeClusterAliasFromIndexExpression(Request request) {
|
|
if (request.index() != null) {
|
|
if (request.index() != null) {
|
|
- String[] split = request.index().split(String.valueOf(RemoteClusterAware.REMOTE_CLUSTER_INDEX_SEPARATOR));
|
|
|
|
- if (split.length > 1) {
|
|
|
|
|
|
+ String[] split = RemoteClusterAware.splitIndexName(request.index());
|
|
|
|
+ if (split[0] != null) {
|
|
/*
|
|
/*
|
|
* if the cluster alias is null and the index field has a clusterAlias (clusterAlias:index notation)
|
|
* if the cluster alias is null and the index field has a clusterAlias (clusterAlias:index notation)
|
|
* that means this is executing on a remote cluster (it was forwarded by the querying cluster).
|
|
* that means this is executing on a remote cluster (it was forwarded by the querying cluster).
|
|
@@ -565,9 +556,6 @@ public class PainlessExecuteAction {
|
|
* We need to strip off the clusterAlias from the index before executing the script locally,
|
|
* We need to strip off the clusterAlias from the index before executing the script locally,
|
|
* so it will resolve to a local index
|
|
* so it will resolve to a local index
|
|
*/
|
|
*/
|
|
- assert split.length == 2
|
|
|
|
- : "If the index contains the REMOTE_CLUSTER_INDEX_SEPARATOR it should have only two parts but it has "
|
|
|
|
- + Arrays.toString(split);
|
|
|
|
request.index(split[1]);
|
|
request.index(split[1]);
|
|
}
|
|
}
|
|
}
|
|
}
|