---
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/4371/api/doc/kibana/v9/operation/operation-put-streams-name-queries-queryid
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v9/operation/operation-put-streams-name-queries-queryid
products:
  - Kibana
---

# Upsert a query to a stream

deprecated

Availability: 9.1+

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

## Paths

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

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

#### Path Parameters

- `name` (string · max: 255)
  The name of the stream.
- `queryId` (string · max: 255)
  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.<br/><br/>[Required authorization] Route required privileges: manage_stream.

## Request Body

`application/json`

- `description` (string · max: 10000) — optional
- `esql` (object) — required
  - `query` (string · max: 10000) — required
- `evidence` ([] string) — optional
- `expires_at` (string · 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: 1) — required
  A non-empty string.

## Response

The query was added or updated successfully.

## Code Examples

#### Console

```console
PUT /api/streams/{name}/queries/{queryId}
{
  "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 "https://{kibana_url}/api/streams/{name}/queries/{queryId}" \
  -H "kbn-xsrf: true" \
  -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"
}'
```

