capabilities.work

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

Upsert a document into an index keyed on a business field rather than the internal document id.

  1. 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.
  2. Merge the payload into the document that matched the business key. Fields absent from the payload are preserved.
  3. 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.