File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
server/src/main/java/org/elasticsearch/persistent Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -474,7 +474,18 @@ default void onTimeout(TimeValue timeout) {
474474 }
475475
476476 private Client getDefaultOrProjectClient (@ Nullable ProjectId projectId ) {
477- return projectId == null ? client : client .projectClient (projectId );
477+ if (projectId == null ) {
478+ return client ;
479+ }
480+
481+ final var currentProjectId = client .projectResolver ().getProjectId ();
482+ if (projectId .equals (currentProjectId )) {
483+ // The projectId will already be used in the client through thread context, so no need to set it again
484+ return client ;
485+ } else {
486+ // Execute will throw if the projectId conflicts with the one in the current context
487+ return client .projectClient (projectId );
488+ }
478489 }
479490
480491 /**
You can’t perform that action at this time.
0 commit comments