Upsert a Document by Business Key
A 3-step recipe with Elasticsearch. We can help you get access.
Recipe · 3 steps
Upsert a Document by Business Key
with Elasticsearch
Upsert a document into an index keyed on a business field rather than the internal document id.
- Run a term query on the key field, asking for at most one hit. A zero-hit response is a valid answer here and drives the create branch.
- Merge the payload into the document that matched the business key. Fields absent from the payload are preserved.
- Index a new document at the supplied id when no existing document carried the business key.
What you'll need to have ready
- index: The index to upsert the document into.
- keyField: The keyword field used to detect an existing document (e.g. "sku").
- keyValue: The business key value to match on.
- document: The document field values to write.
- newDocumentId: The document id to use when no existing document matched.
For your developer
Arazzo workflow elasticsearch:upsert-document, 3 operations: searchDsl → updateDocument → indexDocument. Specs on APIs.io.