Skip to content

Notify items if an error occurs in bulk indexer #615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions esutil/bulk_indexer.go
Original file line number Diff line number Diff line change
@@ -573,6 +573,7 @@ func (w *worker) flush(ctx context.Context) error {
if w.bi.config.OnError != nil {
w.bi.config.OnError(ctx, fmt.Errorf("flush: %s", err))
}
w.notifyItemsOnError(ctx, err)
return fmt.Errorf("flush: %s", err)
}
if res.Body != nil {
@@ -584,6 +585,7 @@ func (w *worker) flush(ctx context.Context) error {
if w.bi.config.OnError != nil {
w.bi.config.OnError(ctx, fmt.Errorf("flush: %s", res.String()))
}
w.notifyItemsOnError(ctx, err)
return fmt.Errorf("flush: %s", res.String())
}

@@ -592,6 +594,7 @@ func (w *worker) flush(ctx context.Context) error {
if w.bi.config.OnError != nil {
w.bi.config.OnError(ctx, fmt.Errorf("flush: %s", err))
}
w.notifyItemsOnError(ctx, err)
return fmt.Errorf("flush: error parsing response body: %s", err)
}

@@ -638,6 +641,14 @@ func (w *worker) flush(ctx context.Context) error {
return err
}

func (w *worker) notifyItemsOnError(ctx context.Context, err error) {
for _, item := range w.items {
if item.OnFailure != nil {
item.OnFailure(ctx, item, BulkIndexerResponseItem{}, fmt.Errorf("flush: %w", err))
}
}
}

type defaultJSONDecoder struct{}

func (d defaultJSONDecoder) UnmarshalFromReader(r io.Reader, blk *BulkIndexerResponse) error {