Skip to main content

Source(name).Doc

CRUD on documents. Guide: Manage documents. Works with store and push sources.

Write rules for create, update and batchInsert:

  • Body must be flat. Object values are allowed only for the formats list and geo-point. Otherwise doc/body-not-flat.
  • id and _id are reserved: doc/reserved-field:<name>.
  • Values are converted to the source's field types and validated. Unknown fields are dropped.
  • The raw values are kept in a separate raw index, the converted ones in the main index.

Doc.get(docId)​

GET /api/v2/source/{id}/doc/{docId} → { id, doc } from the main (transformed) index. 404 doc/not-found.

Doc.create(body, options?)​

POST /api/v2/source/{id}/doc with { data: body, ...options }.

Response { id, result: 'created' }, or { id, doc } with { return: true }.

The id is the value of the duplicate-control field if the source uses one (sending the same key again updates that document). Otherwise a random id is generated, so the same payload sent twice creates two documents. See Sources.

Doc.update(docId, body, options?)​

PUT /api/v2/source/{id}/doc/{docId} with { data: body, ...options }.

OptionDescription
update: trueShallow merge over the raw document. Otherwise full replacement
return: trueRespond { id, doc }

Response { result: 'ok' }. 404 doc/not-found when merging into a missing document.

Doc.delete(docId, options?)​

DELETE /api/v2/source/{id}/doc/{docId}[?return=true]. Removes it from both indices. Status 204, or { id, doc } with return.

Doc.batchInsert(docs, options?)​

POST /api/v2/source/{id}/batch with { data: docs, ...options }.

Throws scenid/empty-batch for an empty or non-array docs.

Response { created, updated, failed, total, errors: [{ code, message, path?, id? }], ids? }. ids only with { return: true }. A document in a batch may carry its own _id.

Other errors: batch/invalid-body, doc/customers-source-not-supported, doc/source-type-not-supported, doc/field-type-mismatch.