---
type: api
title: Create a data stream
description: You must have a matching index template with data stream enabled.
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch-serverless/operation/operation-indices-create-data-stream
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/elasticsearch-serverless/operation/operation-indices-create-data-stream
products:
  - Elasticsearch Serverless
---

# Create a data stream

Availability:

## Paths

- `PUT` `/_data_stream/{name}`

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

#### Path Parameters

- `name` (string)
  Name of the data stream, which must meet the following criteria:
Lowercase only;
Cannot include `\`, `/`, `*`, `?`, `"`, `<`, `>`, `|`, `,`, `#`, `:`, or a space character;
Cannot start with `-`, `_`, `+`, or `.ds-`;
Cannot be `.` or `..`;
Cannot be longer than 255 bytes. Multi-byte characters count towards this limit faster.

## Description

You must have a matching index template with data stream enabled.

## Required authorization

* Index privileges: `create_index`

## Query String Parameters

- `master_timeout` (string Duration · default: 30s)
  Period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error.
- `timeout` (string Duration · default: 30s)
  Period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error.

## Response

`application/json`

- `acknowledged` (boolean)
  For a successful response, this value is always true. On failure, an exception is returned instead.
## Code Examples

#### Console

```console
PUT _data_stream/logs-foo-bar
```

#### JavaScript

```javascript
const response = await client.indices.createDataStream({
  name: "logs-foo-bar",
});
```

#### Python

```python
resp = client.indices.create_data_stream(
    name="logs-foo-bar",
)
```

#### curl

```curl
curl -X PUT "$ELASTICSEARCH_URL/_data_stream/logs-foo-bar" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.indices().createDataStream(c -> c
    .name("logs-foo-bar")
);
```

#### C#

```c#
var response = await client.Indices.CreateDataStreamAsync(name: "logs-foo-bar");
```

#### PHP

```php
$resp = $client->indices()->createDataStream([
    "name" => "logs-foo-bar",
]);
```

#### Ruby

```ruby
response = client.indices.create_data_stream(
  name: "logs-foo-bar"
)
```

