Sources
A source is a named, typed collection of documents (think: a table with a schema, an API and charts). It is the single building block of Insights, and Customers entities show up as one too.
Every source, whatever its type, has the same anatomy.
Anatomy
| Part | Description |
|---|---|
| Name | Unique per tenant and cannot be changed after creation. Letters, digits, umlauts, space, - and _. The SDK finds sources by name, so choose it deliberately |
| Source type | How data gets in: store, push, rabbitmq, … See Source types |
| Fields and field types | The schema. Each field has a type that decides how values are stored, filtered and charted |
| Documents | The records. Flat key/value objects |
| State | Whether the source is receiving data (see below) |
| Duplicate control | How the id of a document is determined, so re-sent data updates instead of duplicating |
Documents are flat
A document is a flat object of field names and values. Only the field types list and geo-point may hold arrays or objects. Nested input from queues is flattened with _ (address.city becomes address_city). The names id and _id are reserved.
Field types
The field type is the contract between the raw value you send and what you can do with it later.
| Type | Use for |
|---|---|
string | Text, ids, categories |
integer, float | Numbers you sum, average or compare |
boolean | Flags |
date-iso | ISO 8601 dates and timestamps |
date-format | Dates in a custom text format |
timestamp-seconds, timestamp-millis, timestamp-micros | Epoch numbers |
geo-point | Locations ("lat,lon", [lon, lat], { lat, lon }, GeoJSON, WKT) |
list | Arrays of values |
Fields can also be disabled, have a default value, and define how empty values are handled.
Raw and main data
Every source keeps your data twice:
- Raw: the values exactly as they arrived, all as text.
- Main: the typed values that charts, filters and aggregations use.
This means you can change a field's type later. Scenid re-derives the main data from the raw data. Values that cannot be converted to a type do not block ingestion. They are counted and listed as warnings (grouped by field and error, with sample values) so you can fix the type or the data.
aggregate reads main data by default. Pass raw: true to read the raw data.
A third, internal record, the event log, tracks imports, errors and new fields. It powers the activity list and the throughput sparklines in the app.
State
| State | Meaning |
|---|---|
ANALYZING / ANALYZED | Data sample is being read / fields are ready for review |
RUNNING | Data is being ingested |
SUCCESSFUL | Idle and up to date |
REINDEXING | Field settings changed, main data is being rebuilt |
FAILED, STOPPED, STALE | Needs attention |
Streaming sources (push, RabbitMQ) go back to SUCCESSFUL after a period without data and to RUNNING again when data arrives.
Duplicate control
Duplicate control decides the id of each document:
| Method | Document id | Effect |
|---|---|---|
| Hash | Fingerprint of the content | Re-sending identical data overwrites itself. Idempotent |
| Field | The value of a field you choose (for example orderId) | Re-sending a key updates that document (upsert) |
| Automatic | A random id | Every document is new, nothing is de-duplicated |
Which methods a type offers, and its default, depends on the source type. Set it before the first data arrives: on a store source it locks once data has been ingested.
Enrichments
Sources can be extended at write time with computed fields: join fields from another source (including customers), a scripted formula, or a geo lookup for IP addresses.
What every source gets
aggregatevia REST and the SDK.- Charts and dashboards in the Insights app.
- CSV export (streamed).
- Transform errors and throughput statistics.
- Field-level configuration in the Insights app.
- Use in a transform to build derived, aggregated sources.
Reading a source
const { result } = await sdk.asAdmin().Insights().Source('Orders').aggregate({
size: 5,
fields: ['orderId', 'total']
})
See Query data.