[[index-patterns-runtime-field-api-upsert]]
=== Upsert runtime field API
++++
Upsert runtime field
++++
experimental[] Create or update an existing runtime field
[[index-patterns-runtime-field-upsert-request]]
==== Request
`PUT :/api/index_patterns/index_pattern//runtime_field`
`PUT :/s//api/index_patterns/index_pattern//runtime_field`
[[index-patterns-runtime-field-upsert-params]]
==== Path parameters
`space_id`::
(Optional, string) An identifier for the space. If `space_id` is not provided in the URL, the default space is used.
`index_pattern_id`::
(Required, string) The ID of the index pattern.
[[index-patterns-runtime-field-upsert-body]]
==== Request body
`name`:: (Required, string) The name for a new runtime field or a name of an existing runtime field.
`runtimeField`:: (Required, object) The runtime field definition object.
[[index-patterns-runtime-field-upsert-example]]
==== Examples
Create or update an existing runtime field on an index pattern:
[source,sh]
--------------------------------------------------
$ curl -X PUT api/index_patterns/index_pattern//runtime_field
{
"name": "runtimeFoo",
"runtimeField": {
"type": "long",
"script": {
"source": "emit(doc["foo"].value)"
}
}
}
--------------------------------------------------
// KIBANA
The API returns created or updated runtime field object and updated index pattern object:
[source,sh]
--------------------------------------------------
{
"index_pattern": {...},
"field": {...}
}
--------------------------------------------------