---
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/4493/api/doc/elasticsearch/v8/operation/operation-indices-create-data-stream
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v8/operation/operation-indices-create-data-stream
products:
  - Elasticsearch
---

# Create a data stream

Availability: Generally available since 7.9

## Paths

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

#### Path parameters

- `name` (string) — required
  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`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/guide/en/elasticsearch/reference/current/token-authentication-services.html)

## Query string parameters

- `master_timeout` (string · default: 30s) — optional
  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 · default: 30s) — optional
  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"
)
```

