Skip to content

Commit 23b9df8

Browse files
authored
[Enrich] add logging for when there are search/bulk failures on _execute (#62313)
When calling `_execute` there is a chance that there will be bulk indexing failures or search failures. These will result in the call failing overall. But, no information is provided for troubleshooting the failure. This commit adds logging to indicate the number of failures, and new debug level logging so that failure details can be determined if necessary. closes #60491
1 parent 8447b7a commit 23b9df8

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.apache.logging.log4j.LogManager;
99
import org.apache.logging.log4j.Logger;
10+
import org.apache.logging.log4j.message.ParameterizedMessage;
1011
import org.elasticsearch.ElasticsearchException;
1112
import org.elasticsearch.action.ActionListener;
1213
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
@@ -27,6 +28,7 @@
2728
import org.elasticsearch.action.admin.indices.segments.IndicesSegmentsRequest;
2829
import org.elasticsearch.action.admin.indices.segments.ShardSegments;
2930
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
31+
import org.elasticsearch.action.bulk.BulkItemResponse;
3032
import org.elasticsearch.action.support.master.AcknowledgedResponse;
3133
import org.elasticsearch.client.Client;
3234
import org.elasticsearch.cluster.ClusterState;
@@ -47,6 +49,7 @@
4749
import org.elasticsearch.index.reindex.BulkByScrollResponse;
4850
import org.elasticsearch.index.reindex.ReindexAction;
4951
import org.elasticsearch.index.reindex.ReindexRequest;
52+
import org.elasticsearch.index.reindex.ScrollableHitSource;
5053
import org.elasticsearch.search.builder.SearchSourceBuilder;
5154
import org.elasticsearch.xpack.core.enrich.EnrichPolicy;
5255
import org.elasticsearch.xpack.core.enrich.action.ExecuteEnrichPolicyStatus;
@@ -352,8 +355,45 @@ private void transferDataToEnrichIndex(final String destinationIndexName) {
352355
public void onResponse(BulkByScrollResponse bulkByScrollResponse) {
353356
// Do we want to fail the request if there were failures during the reindex process?
354357
if (bulkByScrollResponse.getBulkFailures().size() > 0) {
358+
logger.warn(
359+
"Policy [{}]: encountered [{}] bulk failures. Turn on DEBUG logging for details.",
360+
policyName,
361+
bulkByScrollResponse.getBulkFailures().size()
362+
);
363+
if (logger.isDebugEnabled()) {
364+
for (BulkItemResponse.Failure failure : bulkByScrollResponse.getBulkFailures()) {
365+
logger.debug(
366+
new ParameterizedMessage(
367+
"Policy [{}]: bulk index failed for index [{}], id [{}]",
368+
policyName,
369+
failure.getIndex(),
370+
failure.getId()
371+
),
372+
failure.getCause()
373+
);
374+
}
375+
}
355376
listener.onFailure(new ElasticsearchException("Encountered bulk failures during reindex process"));
356377
} else if (bulkByScrollResponse.getSearchFailures().size() > 0) {
378+
logger.warn(
379+
"Policy [{}]: encountered [{}] search failures. Turn on DEBUG logging for details.",
380+
policyName,
381+
bulkByScrollResponse.getSearchFailures().size()
382+
);
383+
if (logger.isDebugEnabled()) {
384+
for (ScrollableHitSource.SearchFailure failure : bulkByScrollResponse.getSearchFailures()) {
385+
logger.debug(
386+
new ParameterizedMessage(
387+
"Policy [{}]: search failed for index [{}], shard [{}] on node [{}]",
388+
policyName,
389+
failure.getIndex(),
390+
failure.getShardId(),
391+
failure.getNodeId()
392+
),
393+
failure.getReason()
394+
);
395+
}
396+
}
357397
listener.onFailure(new ElasticsearchException("Encountered search failures during reindex process"));
358398
} else {
359399
logger.info(

0 commit comments

Comments
 (0)