From 1e0bc1b8aae96655d68445d00769ce7138cfb167 Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Thu, 7 Dec 2023 15:33:28 -0600 Subject: [PATCH] fixing ResultsPersisterService --- .../ml/utils/persistence/ResultsPersisterService.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/utils/persistence/ResultsPersisterService.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/utils/persistence/ResultsPersisterService.java index e69879b654600..08c52c9c51b74 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/utils/persistence/ResultsPersisterService.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/utils/persistence/ResultsPersisterService.java @@ -147,11 +147,12 @@ public BulkResponse indexWithRetry( Supplier shouldRetry, Consumer retryMsgHandler ) throws IOException { - BulkRequest bulkRequest = new BulkRequest().setRefreshPolicy(refreshPolicy); - try (XContentBuilder content = object.toXContent(XContentFactory.jsonBuilder(), params)) { - bulkRequest.add(new IndexRequest(indexName).id(id).source(content).setRequireAlias(requireAlias)); + try (BulkRequest bulkRequest = new BulkRequest().setRefreshPolicy(refreshPolicy)) { + try (XContentBuilder content = object.toXContent(XContentFactory.jsonBuilder(), params)) { + bulkRequest.add(new IndexRequest(indexName).id(id).source(content).setRequireAlias(requireAlias)); + } + return bulkIndexWithRetry(bulkRequest, jobId, shouldRetry, retryMsgHandler); } - return bulkIndexWithRetry(bulkRequest, jobId, shouldRetry, retryMsgHandler); } public void indexWithRetry(