---
type: api
title: "Upsert a query to a stream"
description: "Adds a query to a stream. Noop if the query is already present on the stream. [Required authorization] Route required privileges: manage_stream."
url: https://www.elastic.co/elastic/docs-builder/docs/5111/api/kibana/operation/operation-put-streams-name-queries-queryid
resource: https://www.elastic.co/elastic/docs-builder/docs/5111/api/kibana/operation/operation-put-streams-name-queries-queryid
products:
  - Kibana
---

# Upsert a query to a stream

deprecated

Authentication: required

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

- `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.
- `name` (string · max length: 255) — required
  The name of the stream.
- `queryId` (string · max length: 255) — required
  The identifier of the query.

## Description

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

## Required privileges

- Privileges: `manage_stream`

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

## Responses

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"
  }'
```

