Skip to main content

Elasticsearch / OpenSearch Destination

Bulk-index DWH rows into Elasticsearch (or API-compatible OpenSearch) via the _bulk API — one HTTP round-trip per batch, powering search UIs and dashboards (Kibana / OpenSearch Dashboards). Uses only core httpx; no client library, no extra install.

YAML Example​

destination:
type: elasticsearch
url: https://localhost:9200
api_key_env: ES_API_KEY
index: customers
id_field: user_id # row field → document _id (omit for auto-generated ids)
op_type: index # "index" (upsert) | "create" (insert-only)

Configuration​

FieldTypeDefaultDescription
type"elasticsearch"—Required
urlstring—Cluster base URL (e.g. https://localhost:9200)
indexstring—Target index name
id_fieldstring | nullnullRow field whose value becomes the document _id. Omit → the cluster auto-generates ids
op_typeindex | createindexindex upserts (replace-if-exists); create inserts only (409 if the _id exists)
api_keystring | nullnullAPI key (direct value)
api_key_envstring | nullnullEnv var holding the API key
username_envstring | nullnullEnv var holding the HTTP Basic username
password_envstring | nullnullEnv var holding the HTTP Basic password
verify_tlsbooltrueSet false for self-signed dev clusters
retryobject | nullnullPer-destination retry override (see sync.retry)

Authentication​

Provide one of:

API key (recommended) — Authorization: ApiKey <key>:

api_key_env: ES_API_KEY
export ES_API_KEY="VnVhQ2ZHY0JDZGJrU..." # base64 id:api_key from the cluster

HTTP Basic — username + password:

username_env: ES_USER
password_env: ES_PASS

Without either, the sync fails fast with a clear config error.

Document shape​

Each source row becomes one document. The whole row is the document _source. If id_field is set, that field's value becomes the _id (so re-runs update the same document under op_type: index); without it, the cluster assigns a random id.

# Row: {"user_id": "u1", "name": "Alice", "tier": "vip"}
# → POST /_bulk
# {"index": {"_index": "customers", "_id": "u1"}}
# {"user_id": "u1", "name": "Alice", "tier": "vip"}

Op types​

op_typeBehaviourUse when
index (default)Upsert — replaces the document if _id already existsKeeping an index in sync with a source table
createInsert-only — a row whose _id already exists fails with 409Append-only event/log indices where duplicates are errors

Per-document error handling​

The _bulk API returns HTTP 200 even when individual documents fail — it sets "errors": true and a per-item error. drt parses the items array and maps each failure back to its source row, so:

  • A 409 on one create row → that row lands in result.row_errors (with the cluster's reason), and the rest of the batch still indexes.
  • A mapping/parse error on one document → same — isolated to that row.
  • A whole-batch HTTP failure (401 auth, 5xx after retries) → every row in the batch is recorded as failed.

on_error: skip (the typical choice here) keeps the sync going past per-row failures; on_error: fail stops at the first rejected document.

OpenSearch​

OpenSearch shares the same _bulk API surface — point url at your OpenSearch endpoint and it works unchanged. For local OpenSearch with the bundled self-signed certificate, set verify_tls: false.

Notes​

  • (core) — no extra install; uses httpx, already a core dependency.
  • One _bulk POST per sync.batch_size rows. Tune batch_size to your cluster's http.max_content_length (default 100 MB) and document size.
  • Index template / mapping management and ILM policies are out of scope — create the index (and any mappings) on the cluster side first.
  • Use drt run --dry-run to preview the rows that would be indexed before a real run.

References​