2626import org .elasticsearch .cluster .block .ClusterBlockLevel ;
2727import org .elasticsearch .cluster .metadata .ComponentTemplate ;
2828import org .elasticsearch .cluster .metadata .ComposableIndexTemplate ;
29- import org .elasticsearch .cluster .metadata .Metadata ;
3029import org .elasticsearch .cluster .metadata .ProjectId ;
3130import org .elasticsearch .cluster .metadata .ProjectMetadata ;
3231import org .elasticsearch .cluster .project .ProjectResolver ;
3332import org .elasticsearch .cluster .service .ClusterService ;
3433import org .elasticsearch .common .io .stream .Writeable ;
3534import org .elasticsearch .common .util .concurrent .EsExecutors ;
3635import org .elasticsearch .core .Assertions ;
37- import org .elasticsearch .core .FixForMultiProject ;
3836import org .elasticsearch .core .Releasable ;
3937import org .elasticsearch .core .TimeValue ;
4038import org .elasticsearch .index .IndexingPressure ;
@@ -193,34 +191,33 @@ private boolean applyPipelines(Task task, BulkRequest bulkRequest, Executor exec
193191 boolean hasIndexRequestsWithPipelines = false ;
194192 ClusterState state = clusterService .state ();
195193 ProjectId projectId = projectResolver .getProjectId ();
196- final Metadata metadata ;
194+ final ProjectMetadata project ;
197195 Map <String , ComponentTemplate > componentTemplateSubstitutions = bulkRequest .getComponentTemplateSubstitutions ();
198196 Map <String , ComposableIndexTemplate > indexTemplateSubstitutions = bulkRequest .getIndexTemplateSubstitutions ();
199197 if (bulkRequest .isSimulated ()
200198 && (componentTemplateSubstitutions .isEmpty () == false || indexTemplateSubstitutions .isEmpty () == false )) {
201199 /*
202- * If this is a simulated request, and there are template substitutions, then we want to create and use a new metadata that has
200+ * If this is a simulated request, and there are template substitutions, then we want to create and use a new project that has
203201 * those templates. That is, we want to add the new templates (which will replace any that already existed with the same name),
204202 * and remove the indices and data streams that are referred to from the bulkRequest so that we get settings from the templates
205203 * rather than from the indices/data streams.
206204 */
207- Metadata originalMetadata = state .metadata ();
208- @ FixForMultiProject // properly ensure simulated actions work with MP
209- Metadata .Builder simulatedMetadataBuilder = Metadata .builder (originalMetadata );
205+ ProjectMetadata originalProject = state .metadata ().getProject (projectId );
206+ ProjectMetadata .Builder simulatedMetadataBuilder = ProjectMetadata .builder (originalProject );
210207 if (componentTemplateSubstitutions .isEmpty () == false ) {
211208 Map <String , ComponentTemplate > updatedComponentTemplates = new HashMap <>();
212- updatedComponentTemplates .putAll (originalMetadata . getProject ( projectId ) .componentTemplates ());
209+ updatedComponentTemplates .putAll (originalProject .componentTemplates ());
213210 updatedComponentTemplates .putAll (componentTemplateSubstitutions );
214211 simulatedMetadataBuilder .componentTemplates (updatedComponentTemplates );
215212 }
216213 if (indexTemplateSubstitutions .isEmpty () == false ) {
217214 Map <String , ComposableIndexTemplate > updatedIndexTemplates = new HashMap <>();
218- updatedIndexTemplates .putAll (originalMetadata . getProject ( projectId ) .templatesV2 ());
215+ updatedIndexTemplates .putAll (originalProject .templatesV2 ());
219216 updatedIndexTemplates .putAll (indexTemplateSubstitutions );
220217 simulatedMetadataBuilder .indexTemplates (updatedIndexTemplates );
221218 }
222219 /*
223- * We now remove the index from the simulated metadata to force the templates to be used. Note that simulated requests are
220+ * We now remove the index from the simulated project to force the templates to be used. Note that simulated requests are
224221 * always index requests -- no other type of request is supported.
225222 */
226223 for (DocWriteRequest <?> actionRequest : bulkRequest .requests ) {
@@ -236,12 +233,11 @@ private boolean applyPipelines(Task task, BulkRequest bulkRequest, Executor exec
236233 }
237234 }
238235 }
239- metadata = simulatedMetadataBuilder .build ();
236+ project = simulatedMetadataBuilder .build ();
240237 } else {
241- metadata = state .getMetadata ( );
238+ project = state .metadata (). getProject ( projectId );
242239 }
243240
244- ProjectMetadata project = metadata .getProject (projectId );
245241 Map <String , IngestService .Pipelines > resolvedPipelineCache = new HashMap <>();
246242 for (DocWriteRequest <?> actionRequest : bulkRequest .requests ) {
247243 IndexRequest indexRequest = getIndexWriteRequest (actionRequest );
0 commit comments