---
type: api
title: Convert an index alias to a data stream
description: Converts an index alias to a data stream.
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch-serverless/operation/operation-indices-migrate-to-data-stream
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch-serverless/operation/operation-indices-migrate-to-data-stream
products:
  - Elasticsearch Serverless
---

# Convert an index alias to a data stream

## Paths

- `POST` `/_data_stream/_migrate/{name}`

#### Path parameters

- `name` (string) — required
  Name of the index alias to convert to a data stream.

## Description

Converts an index alias to a data stream.
You must have a matching index template that is data stream enabled.
The alias must meet the following criteria:
The alias must have a write index;
All indices for the alias must have a `@timestamp` field mapping of a `date` or `date_nanos` field type;
The alias must not have any filters;
The alias must not use custom routing.
If successful, the request removes the alias and creates a data stream with the same name.
The indices for the alias become hidden backing indices for the stream.
The write index for the alias becomes the write index for the stream.

## Required authorization

- Index privileges: `manage`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs use 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}"
  ```
  
  For more information about where to find API keys for the Elasticsearch endpoint (${ES_URL}) for a project, go to [Get started with Elasticsearch Serverless](https://www.elastic.co/docs/solutions/search/serverless-elasticsearch-get-started).

## 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
POST _data_stream/_migrate/my-time-series-data
```

#### JavaScript

```javascript
const response = await client.indices.migrateToDataStream({
  name: "my-time-series-data",
});
```

#### Python

```python
resp = client.indices.migrate_to_data_stream(
    name="my-time-series-data",
)
```

#### curl

```curl
curl -X POST "$ELASTICSEARCH_URL/_data_stream/_migrate/my-time-series-data" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.indices().migrateToDataStream(m -> m
    .name("my-time-series-data")
);
```

#### C#

```c#
var response = await client.Indices.MigrateToDataStreamAsync(name: "my-time-series-data");
```

#### PHP

```php
$resp = $client->indices()->migrateToDataStream([
    "name" => "my-time-series-data",
]);
```

#### Ruby

```ruby
response = client.indices.migrate_to_data_stream(
  name: "my-time-series-data"
)
```

