Bulk index documents into OpenSearch or Elasticsearch efficiently while handling backpressure

domain: opensearch · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Use the Bulk API endpoint POST /_bulk which accepts newline-delimited JSON (NDJSON): alternate action lines ({"index":{"_index":"<name>","_id":"<id>"}}) with source document lines; each pair is one operation; end the body with a trailing newline
  2. Target bulk request sizes of 5–15 MiB per request and 1,000–5,000 documents per batch as a starting point; tune based on document size and cluster capacity — too-large batches cause GC pressure and timeouts, too-small batches waste HTTP overhead
  3. Check the bulk response body for per-item errors even on HTTP 200 responses — the bulk API returns 200 even when individual items fail; iterate over the items array and check errors: true on each entry to identify and retry failed documents
  4. Handle backpressure by watching for HTTP 429 (Too Many Requests) with an es_rejected_execution_exception; implement exponential backoff with jitter and retry the entire batch; do not drop documents on 429
  5. Tune indexing performance: set refresh_interval to 30s or -1 during bulk loads (disable auto-refresh) and increase number_of_replicas to 0 during initial load, then restore both after loading; this significantly improves ingest throughput
  6. Use the _bulk API with routing specified in the action metadata to target specific shards and reduce coordination overhead for high-volume writes into time-series indexes

Known gotchas

Related routes

Backfill a DynamoDB Global Secondary Index and manage on-demand capacity during creation
aws-dynamodb · 6 steps · unrated
Bulk-search Jira issues with JQL and pagination
atlassian-jira · 4 steps · unrated
Implement SCIM 2.0 bulk operations with bulkId references and per-operation error handling
rfc-editor.org · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans