---
type: api
title: Upsert a query to a stream
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/kibana/v9/operation/operation-put-streams-name-queries-queryid
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/kibana/v9/operation/operation-put-streams-name-queries-queryid
products:
  - Kibana
---

# Upsert a query to a stream

deprecated

Availability: Experimental since 9.1

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

## Paths

- `PUT` `/api/streams/{name}/queries/{queryId}`
- `PUT` `/s/{space_id}/api/streams/{name}/queries/{queryId}`

#### Path parameters

- `name` (string · max length: 255) — required
  The name of the stream.
- `queryId` (string · max length: 255) — required
  The identifier of the query.

## Description

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

Adds a query to a stream. Noop if the query is already present on the stream.

## Required authorization

- Privileges: `manage_stream`

## 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>`

## Header parameters

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

## Request body

`application/json`

- `description` (string · max length: 10000) — optional
- `esql` (object) — required
  - `query` (string · max length: 10000) — required
- `evidence` (string[]) — optional
- `expires_at` (string · format: date-time · pattern: ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$) — optional
- `severity_score` (number) — optional
- `title` (string · min length: 1) — required
  A non-empty string.

## Response

The query was added or updated successfully.

## Code examples

#### Console

```console
PUT kbn:/api/streams/NAME/queries/QUERY_ID
{
  "description": "Count error-level log events grouped by host name",
  "esql": {
    "query": "FROM logs* | WHERE log.level == \u0022error\u0022 | STATS count = COUNT(*) BY host.name"
  },
  "title": "Error count by host"
}
```

#### curl

```curl
curl -X PUT "${KIBANA_URL}/api/streams/${NAME}/queries/${QUERY_ID}" \
  -H "kbn-xsrf: true" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "Count error-level log events grouped by host name",
    "esql": {
      "query": "FROM logs* | WHERE log.level == \u0022error\u0022 | STATS count = COUNT(*) BY host.name"
    },
    "title": "Error count by host"
  }'
```

