Namespace

Doc

Doc

Document-level operations scoped to this source.

View Source services/InsightsService.class.js, line 113

Methods

# static batchInsert(docs, optionsopt) → {Promise.<ServiceResponse>}

Inserts multiple documents in a single bulk request.

Each document is independently transformed and hashed. The response includes counts of created and updated documents and a per-document error list for any that failed ES indexing. Pass return: true to include the computed document IDs in the response.

The batch endpoint also accepts Content-Type: application/x-ndjson for streaming ingestion from tools like Vector — in that case send raw JSONL lines directly without the { data } envelope.

Parameters:
Name Type Attributes Description
docs Array.<Object>

Array of flat document objects.

options Object <optional>
return boolean <optional>

When true, includes ids (array of doc IDs) in the response.

View Source services/InsightsService.class.js, line 219

scenid/empty-batchdocs is empty or not an array.

Error
Promise.<ServiceResponse>
Example
const { result } = await insights.Source('Orders').Doc.batchInsert([
  { temperature: 21.5, location: 'Berlin' },
  { temperature: 19.0, location: 'Hamburg' }
], { return: true })
// result.created, result.updated, result.failed, result.ids

# static create(body, optionsopt) → {Promise.<ServiceResponse>}

Creates a new document in the source.

The document is run through the source's field type transformations and stored in both the raw index (original values) and the main index (transformed values). The document ID is derived from a hash of the raw field values, making creates idempotent for identical payloads.

Parameters:
Name Type Attributes Description
body Object

Flat document object (no nested keys, no _id or id fields).

options Object <optional>
return boolean <optional>

When true, returns { id, doc } instead of { id, result: 'created' }.

View Source services/InsightsService.class.js, line 145

Promise.<ServiceResponse>
Example
const { result } = await insights.Source('Orders').Doc.create(
  { temperature: 21.5, location: 'Berlin' },
  { return: true }
)
// result.id, result.doc

# static delete(docId, optionsopt) → {Promise.<ServiceResponse>}

Deletes a document from both the raw and main indices.

Parameters:
Name Type Attributes Description
docId string

The document's identifier.

options Object <optional>
return boolean <optional>

When true, returns { id, doc } with the deleted document instead of 204.

View Source services/InsightsService.class.js, line 188

Promise.<ServiceResponse>
Example
const { result } = await insights.Source('Orders').Doc.delete('doc-abc', { return: true })
// result.id, result.doc

# static get(docId) → {Promise.<ServiceResponse>}

Fetches a single document by its ID from the main (transformed) index.

Parameters:
Name Type Description
docId string

The document's identifier.

View Source services/InsightsService.class.js, line 120

Promise.<ServiceResponse>

# static update(docId, body, optionsopt) → {Promise.<ServiceResponse>}

Updates an existing document by its ID.

By default this is a full replacement: the incoming body replaces all stored fields. Pass update: true for a merge update — the service fetches the current raw document, shallow-merges your body on top, then re-indexes.

Parameters:
Name Type Attributes Description
docId string

The document's identifier.

body Object

New field values. Must be flat (no nesting, no reserved fields).

options Object <optional>
update boolean <optional>

When true, merges body into the existing document rather than replacing it.

return boolean <optional>

When true, returns the resulting document after indexing.

View Source services/InsightsService.class.js, line 171

Promise.<ServiceResponse>
Example
// Full replacement
await insights.Source('Orders').Doc.update('doc-abc', { temperature: 22.0, location: 'Berlin' })

// Partial update — only changes temperature, keeps other fields
await insights.Source('Orders').Doc.update('doc-abc', { temperature: 22.0 }, { update: true, return: true })