Source(nameOrId)
Returns a handle for one source. Pass the name or the id.
const orders = sdk.asAdmin().Insights().Source('Orders')
The SDK resolves names via GET /api/v2/source and caches the map for five minutes (refresh is skipped if the cache is younger than 10 seconds). Unknown names throw insights/source-not-found.
get(schema = false)
GET /api/v2/source/{sourceId}[?schema=true]
Returns the source with its config, fieldTypes, rawDocCount and totalDocCount. With schema: true the result also includes schema: { validation, render, translations }, a form definition for the source's fields.
const { result } = await orders.get(true)
console.log(result.fieldTypes)
aggregate(params)
POST /api/v2/source/{sourceId}/aggregate. Guide: Query data.
| Parameter | Type | Description |
|---|---|---|
size | number | Rows per page |
from | number | Offset (not with pageKey) |
fields | string[] | Fields to return |
filter | array | Elasticsearch query clauses. Array required |
sort | array | Elasticsearch sort clauses. Array required |
pageKey | array or object | nextPageKey of the previous response (array for document lists, object in composite mode) |
aggs | array | Grouping and metric stages. See the Query reference |
aggMode | 'aggregation' | 'composite' | How aggs are evaluated. Required when aggs is set |
includeFieldTypes | boolean | Include fieldTypes in the response |
raw | boolean | Read the raw (untransformed) documents |
Response: { rows, aggs, aggMode, nextPageKey, filteredDocCount, totalDocCount: { value, relation }, fieldTypes }.
Errors: sdk/aggregate-filter-must-be-array, sdk/aggregate-sort-must-be-array, 404 get-table-data/unknown-source.
push(docs)
POST /api/v2/source/{sourceId}/push. Queues one document or an array. Service tokens and push sources only.
Response { ok: true, queued: n }.
Errors: push/invalid-source-type, push/source-not-ready, push/empty-body.