---
type: api
title: Upsert a Vega library item
description: "Replaces the full state of a Vega library item. If no item exists with the specified ID, a new one is created."
url: https://www.elastic.co/elastic/docs-builder/docs/5002/api/kibana-serverless/operation/operation-put-vega-id
resource: https://www.elastic.co/elastic/docs-builder/docs/5002/api/kibana-serverless/operation/operation-put-vega-id
products:
  - Kibana
---

# Upsert a Vega library item

Authentication: required

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

## Paths

- `PUT` `/api/vega/{id}`
- `PUT` `/s/{space_id}/api/vega/{id}`

#### Path parameters

- `space_id` (string) — optional
  An identifier for the space. If `space_id` is not provided in the URL, the default space is used. Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.
- `id` (string) — required
  The unique ID of the Vega library item to create or update. A new ID must contain only lowercase letters, numbers, hyphens, and underscores.

## Description

Replaces the full state of a Vega library item. If no item exists with the specified ID, a new one is created.

## Header parameters

- `kbn-xsrf` (string) — required
  A required header to protect against CSRF attacks

## Request body

`application/json`

- `description` (string · min length: 0 · max length: 10000) — optional
  A short description of the Vega library item.
- `filters` (union oneOf[] · max items: 100) — optional
  Filters. Applied together with the dashboard filters to Elasticsearch and ES|QL data sources that use `%context%: true`, and to Elasticsearch data sources that use `%dashboard_context-*%` placeholders.
  - **condition**
    A filter that evaluates a single field condition such as equality, range, or existence.
    - `type` (enum) — required
      Values: `condition`
    - `condition` (union oneOf) — required
      A filter condition with strict operator/value type matching.
      - **is** (`operator: is`)
        Matches documents where `field` equals a single specified value.
        - `operator` (enum) — required
          Values: `is`
        - `field` (string) — required
          Name of the document field the condition evaluates.
        - `negate` (boolean) — optional
          When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
        - `value` (union string | number | boolean) — required
          Single value to compare against the field.
      - **is_one_of** (`operator: is_one_of`)
        Matches documents where `field` equals any value in a provided list.
        - `operator` (enum) — required
          Values: `is_one_of`
        - `field` (string) — required
          Name of the document field the condition evaluates.
        - `negate` (boolean) — optional
          When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
        - `value` (union string[] | number[] | boolean[]) — required
          Homogeneous array of values to match against the field.
      - **range** (`operator: range`)
        Matches documents where `field` falls within a specified numeric or date range.
        - `operator` (enum) — required
          Values: `range`
        - `field` (string) — required
          Name of the document field the condition evaluates.
        - `negate` (boolean) — optional
          When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
        - `value` (object) — required
          Boundary values for a range comparison.
          - `format` (string) — optional
            Elasticsearch [date format](https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/mapping-date-format) string applied when parsing date boundary values. For example, `strict_date_optional_time` or `epoch_millis`.
          - `gt` (number | string) — optional
            Greater than.
          - `gte` (number | string) — optional
            Greater than or equal to.
          - `lt` (number | string) — optional
            Less than.
          - `lte` (number | string) — optional
            Less than or equal to.
      - **exists** (`operator: exists`)
        Matches documents where `field` exists and contains a non-null value.
        - `operator` (enum) — required
          Values: `exists`
        - `field` (string) — required
          Name of the document field the condition evaluates.
        - `negate` (boolean) — optional
          When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
    - `controlled_by` (string) — optional
      Identifier of the panel that manages this filter. When set, the filter is treated as owned by that panel.
    - `data_view_id` (string) — optional
      Identifier of the data view used as context for this filter.
    - `disabled` (boolean) — optional
      When `true`, the filter is inactive and does not affect query results. Defaults to `false`.
    - `is_multi_index` (boolean) — optional
      When `true`, the filter can be applied across multiple indices. Defaults to `false`.
    - `label` (string) — optional
      Human-readable label for the filter, used for display purposes.
    - `negate` (boolean) — optional
      When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
  - **group**
    A filter that combines multiple conditions or nested groups using a logical `and` or `or` operator.
    - `type` (enum) — required
      Values: `group`
    - `controlled_by` (string) — optional
      Identifier of the panel that manages this filter. When set, the filter is treated as owned by that panel.
    - `data_view_id` (string) — optional
      Identifier of the data view used as context for this filter.
    - `disabled` (boolean) — optional
      When `true`, the filter is inactive and does not affect query results. Defaults to `false`.
    - `group` (object) — required
      Logical group that combines one or more conditions or nested groups.
      - `conditions` (union anyOf[]) — required — recursive
        Ordered list of conditions or nested groups combined by the group `operator`.
      - `operator` (enum) — required
        Logical operator applied across all entries in `conditions`. Use `and` to require all conditions, or `or` to require at least one.
        Values: `and`, `or`
    - `is_multi_index` (boolean) — optional
      When `true`, the filter can be applied across multiple indices. Defaults to `false`.
    - `label` (string) — optional
      Human-readable label for the filter, used for display purposes.
    - `negate` (boolean) — optional
      When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
  - **dsl**
    A filter expressed as a raw [Elasticsearch Query DSL](https://www.elastic.co/docs/reference/query-languages/querydsl) object, used for queries that cannot be represented by condition or group filters.
    - `type` (enum) — required
      Values: `dsl`
    - `controlled_by` (string) — optional
      Identifier of the panel that manages this filter. When set, the filter is treated as owned by that panel.
    - `data_view_id` (string) — optional
      Identifier of the data view used as context for this filter.
    - `disabled` (boolean) — optional
      When `true`, the filter is inactive and does not affect query results. Defaults to `false`.
    - `dsl` (map string to object) — required
      Elasticsearch Query DSL object passed directly to the query.
    - `field` (string) — optional
      Field name for scripted filters where the field cannot be extracted from the DSL query.
    - `is_multi_index` (boolean) — optional
      When `true`, the filter can be applied across multiple indices. Defaults to `false`.
    - `label` (string) — optional
      Human-readable label for the filter, used for display purposes.
    - `negate` (boolean) — optional
      When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
    - `params` (object) — optional
      Filter parameters metadata. May contain display values, formats, and parameters for scripted filters.
  - **spatial**
    A filter that applies an Elasticsearch geo query, used for geographic boundary and shape matching.
    - `type` (enum) — required
      Values: `spatial`
    - `controlled_by` (string) — optional
      Identifier of the panel that manages this filter. When set, the filter is treated as owned by that panel.
    - `data_view_id` (string) — optional
      Identifier of the data view used as context for this filter.
    - `disabled` (boolean) — optional
      When `true`, the filter is inactive and does not affect query results. Defaults to `false`.
    - `dsl` (map string to object) — required
      Elasticsearch geo query DSL object.
    - `is_multi_index` (boolean) — optional
      When `true`, the filter can be applied across multiple indices. Defaults to `false`.
    - `label` (string) — optional
      Human-readable label for the filter, used for display purposes.
    - `negate` (boolean) — optional
      When `true`, the filter is negated and matches documents that do NOT satisfy the condition. Defaults to `false`.
- `query` (object) — optional
  KQL or Lucene query. Applied together with the dashboard query to Elasticsearch and ES|QL data sources that use `%context%: true`, and to Elasticsearch data sources that use `%dashboard_context-*%` placeholders.
  - `expression` (string · min length: 0 · max length: 1000000) — required
    A query expression in KQL or Lucene syntax.
  - `language` (enum) — required
    Query language. Use `kql` for Kibana Query Language (KQL) or `lucene` for Lucene query syntax.
    Values: `kql`, `lucene`
- `spec` (union oneOf) — required
  The Vega or Vega-Lite specification. Use `{ "format": "hjson", "value": "<hjson-string>" }` for HJSON (comments and unquoted keys are preserved) or `{ "format": "json", "value": { ... } }` for a JSON object.
  - **HJSON spec** (`format: hjson`)
    - `format` (enum) — required
      Values: `hjson`
    - `value` (string · min length: 1 · max length: 1000000) — required
      The Vega or Vega-Lite specification in HJSON format. Comments and unquoted keys are preserved.
  - **JSON spec** (`format: json`)
    - `format` (enum) — required
      Values: `json`
    - `value` (map string to object) — required
      The Vega or Vega-Lite specification as a JSON object.
- `tags` (string[] · max items: 1000 · default: []) — optional
  Tag IDs associated with this library item.
- `title` (string · min length: 1 · max length: 1024) — required
  The Vega library item title.

## Responses

#### `200`

updated

`application/json`

- `data` (object)
  - `description` (string · min length: 0 · max length: 10000)
    A short description of the Vega library item.
  - `filters` (union oneOf[] · max items: 100)
    Filters. Applied together with the dashboard filters to Elasticsearch and ES|QL data sources that use `%context%: true`, and to Elasticsearch data sources that use `%dashboard_context-*%` placeholders.
    Same options as `filters`
  - `query` (object)
    KQL or Lucene query. Applied together with the dashboard query to Elasticsearch and ES|QL data sources that use `%context%: true`, and to Elasticsearch data sources that use `%dashboard_context-*%` placeholders.
    - `expression` (string · min length: 0 · max length: 1000000)
      A query expression in KQL or Lucene syntax.
    - `language` (enum)
      Query language. Use `kql` for Kibana Query Language (KQL) or `lucene` for Lucene query syntax.
      Values: `kql`, `lucene`
  - `spec` (union oneOf)
    The Vega or Vega-Lite specification. Use `{ "format": "hjson", "value": "<hjson-string>" }` for HJSON (comments and unquoted keys are preserved) or `{ "format": "json", "value": { ... } }` for a JSON object.
    - **HJSON spec** (`format: hjson`)
      - `format` (enum)
        Values: `hjson`
      - `value` (string · min length: 1 · max length: 1000000)
        The Vega or Vega-Lite specification in HJSON format. Comments and unquoted keys are preserved.
    - **JSON spec** (`format: json`)
      - `format` (enum)
        Values: `json`
      - `value` (map string to object)
        The Vega or Vega-Lite specification as a JSON object.
  - `tags` (string[] · max items: 1000 · default: [])
    Tag IDs associated with this library item.
  - `title` (string · min length: 1 · max length: 1024)
    The Vega library item title.
- `id` (string)
  The unique ID of the Vega library item, as returned by the create or search endpoints.
- `meta` (object)
  - `created_at` (string)
    Timestamp when the object was created (ISO 8601).
  - `created_by` (string)
    User profile ID of the user who created the object.
  - `managed` (boolean)
    When `true`, the object is managed by Kibana and cannot be edited by users.
  - `owner` (string)
    Identifier of the plugin or team that owns this object.
  - `updated_at` (string)
    Timestamp when the object was last updated (ISO 8601).
  - `updated_by` (string)
    User profile ID of the user who last updated the object.
  - `version` (string)
    Internal version identifier for optimistic concurrency control.
#### `201`

created

`application/json`

- `data` (object)
  - `description` (string · min length: 0 · max length: 10000)
    A short description of the Vega library item.
  - `filters` (union oneOf[] · max items: 100)
    Filters. Applied together with the dashboard filters to Elasticsearch and ES|QL data sources that use `%context%: true`, and to Elasticsearch data sources that use `%dashboard_context-*%` placeholders.
    Same options as `filters`
  - `query` (object)
    KQL or Lucene query. Applied together with the dashboard query to Elasticsearch and ES|QL data sources that use `%context%: true`, and to Elasticsearch data sources that use `%dashboard_context-*%` placeholders.
    - `expression` (string · min length: 0 · max length: 1000000)
      A query expression in KQL or Lucene syntax.
    - `language` (enum)
      Query language. Use `kql` for Kibana Query Language (KQL) or `lucene` for Lucene query syntax.
      Values: `kql`, `lucene`
  - `spec` (union oneOf)
    The Vega or Vega-Lite specification. Use `{ "format": "hjson", "value": "<hjson-string>" }` for HJSON (comments and unquoted keys are preserved) or `{ "format": "json", "value": { ... } }` for a JSON object.
    - **HJSON spec** (`format: hjson`)
      - `format` (enum)
        Values: `hjson`
      - `value` (string · min length: 1 · max length: 1000000)
        The Vega or Vega-Lite specification in HJSON format. Comments and unquoted keys are preserved.
    - **JSON spec** (`format: json`)
      - `format` (enum)
        Values: `json`
      - `value` (map string to object)
        The Vega or Vega-Lite specification as a JSON object.
  - `tags` (string[] · max items: 1000 · default: [])
    Tag IDs associated with this library item.
  - `title` (string · min length: 1 · max length: 1024)
    The Vega library item title.
- `id` (string)
  The unique ID of the Vega library item, as returned by the create or search endpoints.
- `meta` (object)
  - `created_at` (string)
    Timestamp when the object was created (ISO 8601).
  - `created_by` (string)
    User profile ID of the user who created the object.
  - `managed` (boolean)
    When `true`, the object is managed by Kibana and cannot be edited by users.
  - `owner` (string)
    Identifier of the plugin or team that owns this object.
  - `updated_at` (string)
    Timestamp when the object was last updated (ISO 8601).
  - `updated_by` (string)
    User profile ID of the user who last updated the object.
  - `version` (string)
    Internal version identifier for optimistic concurrency control.
#### `400`

bad request

#### `403`

forbidden

## Code examples

#### Console

```console
PUT kbn:/api/vega/7c1d8e40-9b2f-11f0-a5c3-2f6e4b8d9a10
{
  "title": "Top extensions (US, Windows)",
  "spec": {
    "format": "json",
    "value": {
      "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
      "data": {
        "url": {
          "%context%": true,
          "%timefield%": "timestamp",
          "index": "kibana_sample_data_logs",
          "body": {
            "size": 0,
            "aggs": {
              "extensions": {
                "terms": {
                  "field": "extension.keyword"
                }
              }
            }
          }
        },
        "format": {
          "property": "aggregations.extensions.buckets"
        }
      },
      "mark": "bar",
      "encoding": {
        "x": {
          "field": "key",
          "type": "nominal"
        },
        "y": {
          "field": "doc_count",
          "type": "quantitative"
        }
      }
    }
  },
  "query": {
    "expression": "machine.os.keyword : win*",
    "language": "kql"
  },
  "filters": [
    {
      "type": "condition",
      "data_view_id": "90943e30-9a47-11e8-b64d-95841ca0b247",
      "condition": {
        "field": "geo.dest",
        "operator": "is",
        "value": "US"
      }
    },
    {
      "type": "dsl",
      "dsl": {
        "range": {
          "bytes": {
            "gte": 1000
          }
        }
      }
    }
  ]
}
```

#### curl

```curl
curl -X PUT "${KIBANA_URL}/api/vega/7c1d8e40-9b2f-11f0-a5c3-2f6e4b8d9a10" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{
  "title": "Top extensions (US, Windows)",
  "spec": {
    "format": "json",
    "value": {
      "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
      "data": {
        "url": {
          "%context%": true,
          "%timefield%": "timestamp",
          "index": "kibana_sample_data_logs",
          "body": {
            "size": 0,
            "aggs": {
              "extensions": {
                "terms": {
                  "field": "extension.keyword"
                }
              }
            }
          }
        },
        "format": {
          "property": "aggregations.extensions.buckets"
        }
      },
      "mark": "bar",
      "encoding": {
        "x": {
          "field": "key",
          "type": "nominal"
        },
        "y": {
          "field": "doc_count",
          "type": "quantitative"
        }
      }
    }
  },
  "query": {
    "expression": "machine.os.keyword : win*",
    "language": "kql"
  },
  "filters": [
    {
      "type": "condition",
      "data_view_id": "90943e30-9a47-11e8-b64d-95841ca0b247",
      "condition": {
        "field": "geo.dest",
        "operator": "is",
        "value": "US"
      }
    },
    {
      "type": "dsl",
      "dsl": {
        "range": {
          "bytes": {
            "gte": 1000
          }
        }
      }
    }
  ]
}'
```

## Response examples

#### Update Vega library item response

`application/json`

The complete updated state. PUT replaces the entire item, so fields omitted from the request, such as `query` or `filters`, are removed.

```json
{
  "data": {
    "filters": [
      {
        "condition": {
          "field": "geo.dest",
          "operator": "is",
          "value": "US"
        },
        "data_view_id": "90943e30-9a47-11e8-b64d-95841ca0b247",
        "type": "condition"
      },
      {
        "dsl": {
          "range": {
            "bytes": {
              "gte": 1000
            }
          }
        },
        "type": "dsl"
      }
    ],
    "query": {
      "expression": "machine.os.keyword : win*",
      "language": "kql"
    },
    "spec": {
      "format": "json",
      "value": {
        "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
        "data": {
          "format": {
            "property": "aggregations.extensions.buckets"
          },
          "url": {
            "%context%": true,
            "%timefield%": "timestamp",
            "body": {
              "aggs": {
                "extensions": {
                  "terms": {
                    "field": "extension.keyword"
                  }
                }
              },
              "size": 0
            },
            "index": "kibana_sample_data_logs"
          }
        },
        "encoding": {
          "x": {
            "field": "key",
            "type": "nominal"
          },
          "y": {
            "field": "doc_count",
            "type": "quantitative"
          }
        },
        "mark": "bar"
      }
    },
    "title": "Top extensions (US, Windows)"
  },
  "id": "7c1d8e40-9b2f-11f0-a5c3-2f6e4b8d9a10",
  "meta": {
    "created_at": "2026-09-30T10:00:00.000Z",
    "managed": false,
    "updated_at": "2026-09-30T11:00:00.000Z",
    "version": "WzYwLDFd"
  }
}
```

#### Create Vega library item response (via upsert)

`application/json`

Returned when no item existed with the specified ID and a new one was created.

```json
{
  "data": {
    "filters": [
      {
        "condition": {
          "field": "geo.dest",
          "operator": "is",
          "value": "US"
        },
        "data_view_id": "90943e30-9a47-11e8-b64d-95841ca0b247",
        "type": "condition"
      },
      {
        "dsl": {
          "range": {
            "bytes": {
              "gte": 1000
            }
          }
        },
        "type": "dsl"
      }
    ],
    "query": {
      "expression": "machine.os.keyword : win*",
      "language": "kql"
    },
    "spec": {
      "format": "json",
      "value": {
        "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
        "data": {
          "format": {
            "property": "aggregations.extensions.buckets"
          },
          "url": {
            "%context%": true,
            "%timefield%": "timestamp",
            "body": {
              "aggs": {
                "extensions": {
                  "terms": {
                    "field": "extension.keyword"
                  }
                }
              },
              "size": 0
            },
            "index": "kibana_sample_data_logs"
          }
        },
        "encoding": {
          "x": {
            "field": "key",
            "type": "nominal"
          },
          "y": {
            "field": "doc_count",
            "type": "quantitative"
          }
        },
        "mark": "bar"
      }
    },
    "title": "Top extensions (US, Windows)"
  },
  "id": "7c1d8e40-9b2f-11f0-a5c3-2f6e4b8d9a10",
  "meta": {
    "created_at": "2026-09-30T10:00:00.000Z",
    "managed": false,
    "updated_at": "2026-09-30T10:00:00.000Z",
    "version": "WzU5LDFd"
  }
}
```

