@@ -72,7 +72,10 @@ public static Map<String, IndexRewriteResult> rewriteIndexExpressions(
7272 if (canonicalExpressionsMap .containsKey (indexExpression )) {
7373 continue ;
7474 }
75- canonicalExpressionsMap .put (indexExpression , rewriteIndexExpression (indexExpression , originProjectAlias , allProjectAliases ));
75+ canonicalExpressionsMap .put (
76+ indexExpression ,
77+ rewriteIndexExpression (indexExpression , originProjectAlias , allProjectAliases , null )
78+ );
7679 }
7780 return canonicalExpressionsMap ;
7881 }
@@ -85,27 +88,30 @@ public static Map<String, IndexRewriteResult> rewriteIndexExpressions(
8588 * it can match on its actual alias and on the special alias "_origin". Any expression matched by the origin
8689 * project also cannot be qualified with its actual alias in the final rewritten expression.
8790 * @param allProjectAliases the list of all project aliases (linked and origin) consider for a request
91+ * @param projectRouting the project routing that was applied to determine the origin and linked projects.
92+ * {@code null} if no project routing was applied.
8893 * @throws IllegalArgumentException if exclusions, date math or selectors are present in the index expressions
8994 * @throws NoMatchingProjectException if a qualified resource cannot be resolved because a project is missing
9095 */
9196 public static IndexRewriteResult rewriteIndexExpression (
9297 String indexExpression ,
9398 @ Nullable String originProjectAlias ,
94- Set <String > allProjectAliases
99+ Set <String > allProjectAliases ,
100+ @ Nullable String projectRouting
95101 ) {
96102 maybeThrowOnUnsupportedResource (indexExpression );
97103
98104 // Always 404 when no project is available for index resolution. This is matching error handling behaviour for resolving
99105 // projects with qualified index patterns such as "missing-*:index".
100106 if (originProjectAlias == null && allProjectAliases .isEmpty ()) {
101- // TODO: add project_routing string to the exception message
102- throw new NoMatchingProjectException ("no matching project after applying project routing" );
107+ assert projectRouting != null ;
108+ throw new NoMatchingProjectException ("no matching project after applying project routing [" + projectRouting + "] " );
103109 }
104110
105111 final boolean isQualified = RemoteClusterAware .isRemoteIndexName (indexExpression );
106112 final IndexRewriteResult rewrittenExpression ;
107113 if (isQualified ) {
108- rewrittenExpression = rewriteQualifiedExpression (indexExpression , originProjectAlias , allProjectAliases );
114+ rewrittenExpression = rewriteQualifiedExpression (indexExpression , originProjectAlias , allProjectAliases , projectRouting );
109115 logger .debug ("Rewrote qualified expression [{}] to [{}]" , indexExpression , rewrittenExpression );
110116 } else {
111117 rewrittenExpression = rewriteUnqualifiedExpression (indexExpression , originProjectAlias , allProjectAliases );
@@ -146,7 +152,8 @@ private static IndexRewriteResult rewriteUnqualifiedExpression(
146152 private static IndexRewriteResult rewriteQualifiedExpression (
147153 String resource ,
148154 @ Nullable String originProjectAlias ,
149- Set <String > allProjectAliases
155+ Set <String > allProjectAliases ,
156+ @ Nullable String projectRouting
150157 ) {
151158 String [] splitResource = RemoteClusterAware .splitIndexName (resource );
152159 assert splitResource .length == 2
@@ -167,7 +174,7 @@ private static IndexRewriteResult rewriteQualifiedExpression(
167174
168175 if (originProjectAlias == null && ProjectRoutingResolver .ORIGIN .equals (requestedProjectAlias )) {
169176 // handling case where we have a qualified expression like: _origin:indexName but no _origin project is set
170- throw new NoMatchingProjectException (requestedProjectAlias );
177+ throw new NoMatchingProjectException (requestedProjectAlias , projectRouting );
171178 }
172179
173180 try {
@@ -177,7 +184,7 @@ private static IndexRewriteResult rewriteQualifiedExpression(
177184 );
178185
179186 if (allProjectsMatchingAlias .isEmpty ()) {
180- throw new NoMatchingProjectException (requestedProjectAlias );
187+ throw new NoMatchingProjectException (requestedProjectAlias , projectRouting );
181188 }
182189
183190 String localExpression = null ;
@@ -193,7 +200,7 @@ private static IndexRewriteResult rewriteQualifiedExpression(
193200 return new IndexRewriteResult (localExpression , resourcesMatchingLinkedProjectAliases );
194201 } catch (NoSuchRemoteClusterException ex ) {
195202 logger .debug (ex .getMessage (), ex );
196- throw new NoMatchingProjectException (requestedProjectAlias );
203+ throw new NoMatchingProjectException (requestedProjectAlias , projectRouting );
197204 }
198205 }
199206
0 commit comments