Skip to content

Retry bulk import one document per request on 413 - #39

Merged
marcosgz merged 1 commit into
mainfrom
retry-bulk-413-per-document
May 15, 2026
Merged

Retry bulk import one document per request on 413#39
marcosgz merged 1 commit into
mainfrom
retry-bulk-413-per-document

Conversation

@marcosgz

Copy link
Copy Markdown
Owner

Summary

When a bulk import receives RequestEntityTooLargeError (HTTP 413), Esse::Import::Bulk#each_request already retries once with size-balanced chunks (balance_requests_size). If that retry still 413s, the error currently bubbles up and aborts the whole import — even though one or two oversized documents in the batch may be the only problem.

This PR adds a third recovery tier: after the balanced retry, the bulk is split one document per request as a last resort. The error is only raised once a single-document bulk still exceeds the limit (which is the only case where the data is genuinely unimportable).

Changes:

  • New per-document retry tier after balance_requests_size, with a distinct warning so the fallback is observable.
  • Per-document retry also triggers when the 413 message has no parseable byte limit (previously balance_requests_size re-raised immediately, defeating retry).
  • Oversized single documents are no longer silently discarded — they're sent in their own request, so the eventual 413 from the cluster identifies them.
  • New last_retry_per_document: true keyword arg on each_request to opt out.
  • Version bumped to 0.5.0; all Gemfile.lock files refreshed.

Test plan

  • bundle exec rspec spec/esse/import/bulk_spec.rb — 11 examples, 0 failures (includes 4 new examples + 1 updated for the changed discard behavior)
  • Full unit suite (STUB_STACK=elasticsearch-7.17.0 BUNDLE_GEMFILE=gemfiles/Gemfile.elasticsearch-7.x bundle exec rspec --exclude-pattern 'spec/esse/integrations/**/*') — 1017 examples, 0 failures

When a bulk request returns RequestEntityTooLargeError after the existing
size-balancing pass, retry one document per request as a last resort. Only
raise when a single-document bulk still exceeds the limit. Also falls back
to per-document retry when the 413 message has no parseable byte limit,
and sends oversized single docs in their own request instead of silently
discarding them.

Bumps version to 0.5.0.
@marcosgz
marcosgz merged commit e518747 into main May 15, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant