---
type: api
title: Update a saved query
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana-serverless/operation/operation-osqueryupdatesavedquery
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana-serverless/operation/operation-osqueryupdatesavedquery
products:
  - Kibana
---

# Update a saved query

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

## Paths

- `PUT` `/api/osquery/saved_queries/{id}`
- `PUT` `/s/{space_id}/api/osquery/saved_queries/{id}`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/kibana-serverless/authentication#apikeyauth)

#### Path Parameters

- `id` (string)
  The saved query ID.

## Description

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

Update a saved query using the query ID.
> info
> You cannot update a prebuilt saved query.

## Request Body

`application/json`

- `description` (string) — optional
  The saved query description.
- `ecs_mapping` (object) — optional
  Map osquery results columns or static values to Elastic Common Schema (ECS) fields
- `id` (string) — optional
  The ID of a saved query.
- `interval` (string) — optional
  An interval, in seconds, on which to run the query.
- `platform` (string) — optional
  Restricts the query to a specified platform. The default is all platforms. To specify multiple platforms, use commas. For example, `linux,darwin`.
- `query` (string) — optional
  The SQL query you want to run.
- `removed` (boolean) — optional
  Indicates whether the query is removed.
- `snapshot` (boolean) — optional
  Indicates whether the query is a snapshot.
- `version` (string) — optional
  Uses the Osquery versions greater than or equal to the specified version string.

## Response

Indicates a successful call.

`application/json`

- `data` (object)
  - `created_at` (string)
  - `created_by` (string) — nullable
  - `created_by_profile_uid` (string)
  - `description` (string)
    The saved query description.
  - `ecs_mapping` (object)
    Map osquery results columns or static values to Elastic Common Schema (ECS) fields
  - `id` (string)
    The ID of a saved query.
  - `interval` (integer | string)
  - `platform` (string)
    Restricts the query to a specified platform. The default is all platforms. To specify multiple platforms, use commas. For example, `linux,darwin`.
  - `prebuilt` (boolean)
  - `query` (string)
    The SQL query you want to run.
  - `removed` (boolean)
    Indicates whether the query is removed.
  - `saved_object_id` (string)
  - `snapshot` (boolean)
    Indicates whether the query is a snapshot.
  - `timeout` (integer)
  - `updated_at` (string)
  - `updated_by` (string) — nullable
  - `updated_by_profile_uid` (string)
  - `version` (string)
    The saved query version.
## Code Examples

#### Console

```console
PUT /api/osquery/saved_queries/{id}
{
  "description": "Updated saved query description",
  "id": "my_saved_query",
  "interval": "120",
  "platform": "linux,darwin",
  "query": "select * from osquery_info;",
  "timeout": 60
}
```

#### curl

```curl
curl -X PUT "https://{kibana_url}/api/osquery/saved_queries/{id}" \
  -H "Content-Type: application/json" \
  -d '{
  "description": "Updated saved query description",
  "id": "my_saved_query",
  "interval": "120",
  "platform": "linux,darwin",
  "query": "select * from osquery_info;",
  "timeout": 60
}'
```

## Response Examples

#### Saved query updated

```json
{
  "data": {
    "description": "Updated saved query description",
    "id": "my_saved_query",
    "interval": "120",
    "platform": "linux,darwin",
    "query": "select * from osquery_info;",
    "saved_object_id": "42ba1280-2172-11ee-8523-5765fca79a3c",
    "timeout": 60,
    "updated_at": "2025-02-27T10:00:00.000Z",
    "updated_by": "elastic"
  }
}
```

