POST /api/data_views/data_view/{viewId}/runtime_field

Spaces method and path for this operation:

post /s/{space_id}/api/data_views/data_view/{viewId}/runtime_field

Refer to Spaces for more information.

Create a runtime field for a data view. Runtime fields are computed at query time using a Painless script and do not require reindexing. If no script is provided, the runtime field returns the corresponding value from the document _source.

Headers

  • kbn-xsrf string Required

    Cross-site request forgery protection

Path parameters

  • viewId string Required

    An identifier for the data view.

application/json

Body Required

  • name string Required

    The name for a runtime field.

  • runtimeField object Required

    The runtime field definition object.

Responses

  • 200 application/json

    Indicates a successful call.

POST /api/data_views/data_view/{viewId}/runtime_field
curl \
  -X POST "${KIBANA_URL}/api/data_views/data_view/${DATA_VIEW_ID}/runtime_field" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{"name":"hour_of_day","runtimeField":{"type":"long","script":{"source":"emit(doc['"'"'timestamp'"'"'].value.getHour())"}}}'
POST kbn://api/data_views/data_view/{viewId}/runtime_field
{"name":"hour_of_day","runtimeField":{"type":"long","script":{"source":"emit(doc['timestamp'].value.getHour())"}}}
Request example
Create a long-type runtime field that emits a value derived from the foo source field.
{
  "name": "runtimeFoo",
  "runtimeField": {
    "script": {
      "source": "emit(doc[\"foo\"].value)"
    },
    "type": "long"
  }
}