---
type: api
title: Update a runtime field
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/kibana/operation/operation-updateruntimefielddefault
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/kibana/operation/operation-updateruntimefielddefault
products:
  - Kibana
---

# Update a runtime field

- Server: `https://{kibana_url}`

## Paths

- `POST` `/api/data_views/data_view/{viewId}/runtime_field/{fieldName}`
- `POST` `/s/{space_id}/api/data_views/data_view/{viewId}/runtime_field/{fieldName}`

#### Path parameters

- `fieldName` (string) — required
  The name of the runtime field.
  Example: `hour_of_day`
- `viewId` (string) — required
  An identifier for the data view.
  Example: `ff959d40-b880-11e8-a6d9-e546fe2bba5f`

## Description

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

Update an existing runtime field in a data view. Only the fields provided in the request body are updated.

## Authentication

- Api key: `Authorization: <value>`
  These APIs use key-based authentication. You must create an API key and use the encoded value in the request header. For example: `Authorization: ApiKey base64AccessApiKey`
- Basic: `Authorization: Basic <credentials>`

## Request body

`application/json`

- `runtimeField` (object) — required
  The runtime field definition object.

You can update following fields:

- `type`
- `script`

## Responses

#### `200`

Indicates a successful call.

#### `400`

Bad request

`application/json`

- `error` (string)
- `message` (string)
- `statusCode` (number)
## Code examples

#### Console

```console
POST kbn://api/data_views/data_view/{viewId}/runtime_field/{fieldName}
{"runtimeField":{"type":"long","script":{"source":"emit(doc['timestamp'].value.getHour())"}}}
```

#### curl

```curl
curl \
  -X POST "${KIBANA_URL}/api/data_views/data_view/${DATA_VIEW_ID}/runtime_field/${FIELD_NAME}" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{"runtimeField":{"type":"long","script":{"source":"emit(doc['"'"'timestamp'"'"'].value.getHour())"}}}'
```

## Response examples

#### A bad request response.

The request was rejected because the payload or query parameters are missing required fields or contain invalid values.

```json
{
  "error": "Bad Request",
  "message": "[request body.data_view.title]: expected value of type [string] but got [undefined]",
  "statusCode": 400
}
```

