Skip to main content

Fields

Endpoints for managing dataset fields including creation, updates, deletion, locking, and synchronization.

GET /api/datasets/{id}/fields

Get all fields for a dataset, sorted by position and name.

Authentication: Required

Path Parameters:

ParameterTypeDescription
idstringDataset ID or slug

Query Parameters:

ParameterTypeDefaultDescription
samplebooleanfalseInclude sample values for each field

Response:

{
"_links": {
"self": { "href": "/api/datasets/{id}/fields" }
},
"_embedded": {
"inf:field": [
{
"name": "order_id",
"label": "Order ID",
"dataType": "string",
"position": 0,
"visible": true,
"locked": false,
"searchable": true,
"sortable": true,
"filterable": true
},
{
"name": "amount",
"label": "Sale Amount",
"dataType": "number",
"position": 1,
"visible": true,
"locked": false,
"format": {
"type": "currency",
"decimals": 2,
"currency": "USD"
}
},
{
"name": "profit_margin",
"label": "Profit Margin %",
"dataType": "number",
"position": 2,
"visible": true,
"calculated": true,
"script": "doc['revenue'].value - doc['cost'].value",
"scriptLang": "painless"
}
]
},
"start": 0,
"count": 3,
"total": 3
}

With Samples:

GET /api/datasets/sales-2024/fields?sample=true

Returns field objects with sample property containing example values:

{
"_links": {
"self": { "href": "/api/datasets/{id}/fields?sample=true" }
},
"_embedded": {
"inf:field": [
{
"name": "customer_name",
"label": "Customer Name",
"dataType": "string",
"sample": ["Acme Corp", "TechStart Inc", "Global Industries"]
}
]
},
"start": 0,
"count": 1,
"total": 1
}

Field Properties:

PropertyTypeDescription
namestringField identifier (unique within dataset)
labelstringDisplay name
dataTypestringData type: string, number, date, boolean, object
positionintegerDisplay order
visiblebooleanShow in default view
lockedbooleanPrevent user modification
calculatedbooleanComputed field (not from source)
scriptstringCalculation script (for calculated fields)
scriptLangstringScript language (painless, expression)
formatobjectDisplay formatting rules
searchablebooleanEnable full-text search
sortablebooleanEnable sorting
filterablebooleanEnable filtering

POST /api/datasets/{id}/fields

Create a new calculated or custom field.

Authentication: Required

Permission: dataset:write

Path Parameters:

ParameterTypeDescription
idstringDataset ID or slug

Request Body:

FieldTypeRequiredDescription
namestringYesField identifier
labelstringYesDisplay name
dataTypestringYesData type
scriptstringNoCalculation script
fieldIdstringNoSource field ID (for linking)
lockFieldIdbooleanNoLock the source field

Example Request (calculated field):

{
"name": "profit",
"label": "Profit",
"dataType": "number",
"script": "doc['revenue'].value - doc['cost'].value",
"scriptLang": "painless"
}

Example Request (alias field):

{
"name": "sale_date",
"label": "Sale Date",
"dataType": "date",
"fieldId": "order_date",
"lockFieldId": true
}

Response:

Returns the created field object.

Calculated Fields

Use Painless scripting to create derived fields. Common use cases: profit calculations, date transformations, string concatenations, conditional logic.


GET /api/datasets/{datasetId}/fields/{name}

Get a single field by name.

Authentication: Required

Path Parameters:

ParameterTypeDescription
datasetIdstringDataset ID or slug
namestringField name

Response:

{
"name": "amount",
"label": "Sale Amount",
"dataType": "number",
"position": 1,
"visible": true,
"locked": false,
"format": {
"type": "currency",
"decimals": 2,
"currency": "USD"
}
}

PUT /api/datasets/{datasetId}/fields/{name}

Update an existing field.

Authentication: Required

Permission: dataset:write

Path Parameters:

ParameterTypeDescription
datasetIdstringDataset ID or slug
namestringField name

Request Body:

FieldTypeDescription
labelstringDisplay name
dataTypestringData type
positionintegerDisplay order
visiblebooleanShow in default view
formatobjectDisplay formatting
scriptstringCalculation script
lockedbooleanPrevent user modification

Example Request:

{
"label": "Total Sale Amount",
"format": {
"type": "currency",
"decimals": 2,
"currency": "EUR"
},
"position": 5
}

Response:

Returns the updated field object.


DELETE /api/datasets/{datasetId}/fields/{name}

Delete a field from the dataset.

Authentication: Required

Permission: dataset:write

Path Parameters:

ParameterTypeDescription
datasetIdstringDataset ID or slug
namestringField name

Response:

204 No Content

Restrictions:

  • Cannot delete the _snapshots field (reserved for snapshot tracking)
  • Cannot delete locked fields
  • Cannot delete fields used in visuals or filters (returns 400)
Field Deletion

Deleting a field removes it from the dataset schema and makes its data inaccessible. This operation cannot be undone.


POST /api/datasets/{id}/fields-lock

Lock or unlock multiple fields to prevent user modification.

Authentication: Required

Permission: dataset:write

Path Parameters:

ParameterTypeDescription
idstringDataset ID or slug

Request Body:

FieldTypeRequiredDescription
fieldIdsarrayYesArray of field names to lock/unlock
lockbooleanYestrue to lock, false to unlock

Example Request (lock fields):

{
"fieldIds": ["order_id", "customer_id", "order_date"],
"lock": true
}

Example Request (unlock fields):

{
"fieldIds": ["region", "category"],
"lock": false
}

Response:

{
"locked": 3,
"fields": ["order_id", "customer_id", "order_date"]
}

Use Case:

Lock critical fields (IDs, timestamps) to prevent accidental modification by users while allowing flexibility with other fields.


POST /api/datasets/{id}/_syncFields

Synchronize field definitions from the Elasticsearch mapping.

Authentication: Required

Permission: dataset:write

Path Parameters:

ParameterTypeDescription
idstringDataset ID or slug

Response:

{
"added": 3,
"updated": 5,
"removed": 1,
"fields": [...]
}

Behavior:

  • Compares dataset field definitions with Elasticsearch mapping
  • Adds fields that exist in ES but not in dataset
  • Updates field types that have changed
  • Optionally removes fields that no longer exist in ES
  • Preserves custom field properties (labels, formats, positions)

Use Case:

After modifying the dataset query or importing new data, sync fields to ensure the dataset schema matches the actual data structure.

Automatic Sync

Field sync is automatically performed during dataset refresh operations. Manual sync is useful when the Elasticsearch mapping has been modified externally.


POST /api/datasets/{id}/_link-fields

Link dataset fields to datasource fields for query building.

Authentication: Required

Permission: dataset:write

Path Parameters:

ParameterTypeDescription
idstringDataset ID or slug

Response:

{
"linked": 12,
"fields": [
{
"name": "order_id",
"sourceField": "orders.id",
"sourceTable": "orders"
}
]
}

Behavior:

  • Matches dataset fields to datasource schema
  • Creates links for query building and joins
  • Enables intelligent query suggestions
  • Preserves manual field mappings

Use Case:

After creating a dataset from a datasource query, link fields to enable advanced query building features and field suggestions.


Field Data Types

Supported data types and their Elasticsearch mappings:

Data TypeElasticsearch TypeDescription
stringtext, keywordText values
numberlong, doubleNumeric values
datedateDate/time values
booleanbooleanTrue/false values
objectobject, nestedStructured data
geo_pointgeo_pointGeographic coordinates

Field Formatting

Common format configurations:

Currency

{
"type": "currency",
"decimals": 2,
"currency": "USD",
"symbol": "$"
}

Percentage

{
"type": "percentage",
"decimals": 1,
"multiply": true
}

Date

{
"type": "date",
"format": "YYYY-MM-DD",
"timezone": "America/New_York"
}

Number

{
"type": "number",
"decimals": 2,
"thousandsSeparator": true,
"prefix": "#"
}

Calculated Field Examples

Profit Calculation

{
"name": "profit",
"label": "Profit",
"dataType": "number",
"script": "doc['revenue'].value - doc['cost'].value"
}

Profit Margin Percentage

{
"name": "profit_margin",
"label": "Profit Margin %",
"dataType": "number",
"script": "(doc['revenue'].value - doc['cost'].value) / doc['revenue'].value * 100"
}

Full Name Concatenation

{
"name": "full_name",
"label": "Full Name",
"dataType": "string",
"script": "doc['first_name'].value + ' ' + doc['last_name'].value"
}

Days Since Order

{
"name": "days_since_order",
"label": "Days Since Order",
"dataType": "number",
"script": "(System.currentTimeMillis() - doc['order_date'].value.toInstant().toEpochMilli()) / (1000 * 60 * 60 * 24)"
}

Conditional Logic

{
"name": "priority",
"label": "Priority",
"dataType": "string",
"script": "if (doc['amount'].value > 10000) { return 'High'; } else if (doc['amount'].value > 1000) { return 'Medium'; } else { return 'Low'; }"
}

Best Practices

Field Naming

  • Use lowercase with underscores: customer_name, order_date
  • Avoid spaces and special characters
  • Be descriptive but concise
  • Match datasource conventions when possible

Field Organization

  • Set logical positions for related fields
  • Group calculated fields together
  • Place IDs and timestamps first
  • Hide internal/technical fields from default view

Performance

  • Limit calculated field complexity
  • Use keyword type for sorting/filtering
  • Use text type for full-text search
  • Avoid calculated fields in aggregations when possible

Security

  • Lock critical fields (IDs, audit timestamps)
  • Validate scripts before saving
  • Test calculated fields with sample data
  • Document complex calculations