---
type: api
title: Create an index
description: You can use the create index API to add a new index to an Elasticsearch cluster.
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/operation/operation-indices-create
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/operation/operation-indices-create
products:
  - Elasticsearch
---

# Create an index

## Paths

- `PUT` `/{index}`

#### Path parameters

- `index` (string) — required
  Name of the index you wish to create.
Index names must meet the following criteria:

* Lowercase only
* Cannot include `\`, `/`, `*`, `?`, `"`, `<`, `>`, `|`, ` ` (space character), `,`, or `#`
* Indices prior to 7.0 could contain a colon (`:`), but that has been deprecated and will not be supported in later versions
* Cannot start with `-`, `_`, or `+`
* Cannot be `.` or `..`
* Cannot be longer than 255 bytes (note thtat it is bytes, so multi-byte characters will reach the limit faster)
* Names starting with `.` are deprecated, except for hidden indices and internal indices managed by plugins

## Description

You can use the create index API to add a new index to an Elasticsearch cluster.
When creating an index, you can specify the following:

* Settings for the index.
* Mappings for fields in the index.
* Index aliases

**Wait for active shards**

By default, index creation will only return a response to the client when the primary copies of each shard have been started, or the request times out.
The index creation response will indicate what happened.
For example, `acknowledged` indicates whether the index was successfully created in the cluster, `while shards_acknowledged` indicates whether the requisite number of shard copies were started for each shard in the index before timing out.
Note that it is still possible for either `acknowledged` or `shards_acknowledged` to be `false`, but for the index creation to be successful.
These values simply indicate whether the operation completed before the timeout.
If `acknowledged` is false, the request timed out before the cluster state was updated with the newly created index, but it probably will be created sometime soon.
If `shards_acknowledged` is false, then the request timed out before the requisite number of shards were started (by default just the primaries), even if the cluster state was successfully updated to reflect the newly created index (that is to say, `acknowledged` is `true`).

You can change the default of only waiting for the primary shards to start through the index setting `index.write.wait_for_active_shards`.
Note that changing this setting will also affect the `wait_for_active_shards` value on all subsequent write operations.

## Required authorization

- Index privileges: `create_index`, `manage`

## 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/docs/deploy-manage/users-roles/cluster-or-deployment-auth/token-based-authentication-services)

## 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.
- `wait_for_active_shards` (union · default: 1) — optional
  The number of shard copies that must be active before proceeding with the operation.
Set to `all` or any positive integer up to the total number of shards in the index (`number_of_replicas+1`).
  Values: `all`, `index-setting`

## Request body

`application/json`

- `aliases` (map string to object) — optional
  Aliases for the index.
  Map values (object)
  - `filter` ({} Query) — optional
    Query used to limit documents the alias can access.
    See [Query](https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/types/_types-query_dsl-querycontainer)
  - `index_routing` (string) — optional
    Value used to route indexing operations to a specific shard.
If specified, this overwrites the `routing` value for indexing operations.
  - `is_hidden` (boolean · default: false) — optional
    If `true`, the alias is hidden.
All indices for the alias must have the same `is_hidden` value.
  - `is_write_index` (boolean · default: false) — optional
    If `true`, the index is the write index for the alias.
  - `routing` (string) — optional
    Value used to route indexing and search operations to a specific shard.
  - `search_routing` (string) — optional
    Value used to route search operations to a specific shard.
If specified, this overwrites the `routing` value for search operations.
- `mappings` (object) — optional
  Mapping for fields in the index. If specified, this mapping can include:
- Field names
- Field data types
- Mapping parameters
  - `all_field` (object) — optional
    - `analyzer` (string) — required
    - `enabled` (boolean) — required
    - `omit_norms` (boolean) — required
    - `search_analyzer` (string) — required
    - `similarity` (string) — required
    - `store` (boolean) — required
    - `store_term_vector_offsets` (boolean) — required
    - `store_term_vector_payloads` (boolean) — required
    - `store_term_vector_positions` (boolean) — required
    - `store_term_vectors` (boolean) — required
  - `date_detection` (boolean) — optional
  - `dynamic` (enum) — optional
    Values: `strict`, `runtime`, `true`, `false`
  - `dynamic_date_formats` (string[]) — optional
  - `dynamic_templates` (string to object[]) — optional
  - `_field_names` (object) — optional
    - `enabled` (boolean) — required
  - `index_field` (object) — optional
    - `enabled` (boolean) — required
  - `_meta` (object) — optional
  - `numeric_detection` (boolean) — optional
  - `properties` (map string to oneOf) — optional
  - `_routing` (object) — optional
    - `required` (boolean) — required
  - `_size` (object) — optional
    - `enabled` (boolean) — required
  - `_source` (object) — optional
    - `enabled` (boolean) — optional
    - `excludes` (string[]) — optional
    - `includes` (string[]) — optional
    - `mode` (enum) — optional
      

Supported values include:
  - `disabled`
  - `stored`
  - `columnar_stored`
  - `synthetic`: Instead of storing source documents on disk exactly as you send them,
 Elasticsearch can reconstruct source content on the fly upon retrieval.
      Values: `disabled`, `stored`, `columnar_stored`, `synthetic`
  - `runtime` (map string to object) — optional
    Map values (object)
    - `fields` (map string to object) — optional
      For type `composite`
      Map values (object)
      - `type` (enum) — required
        Values: `boolean`, `composite`, `date`, `double`, `geo_point`, `geo_shape`, `ip`, `keyword`, `long`, `lookup`
    - `fetch_fields` (object[]) — optional
      For type `lookup`
      - `field` (string) — required
      - `format` (string) — optional
    - `format` (string) — optional
      A custom format for `date` type runtime fields.
    - `input_field` (string) — optional
      For type `lookup`
    - `target_field` (string) — optional
      For type `lookup`
    - `target_index` (string) — optional
      For type `lookup`
    - `script` (string) — optional
      Painless script executed at query time.
    - `on_script_error` (enum) — optional
      Values: `fail`, `continue`
    - `type` (enum) — required
      Field type, which can be: `boolean`, `composite`, `date`, `double`, `geo_point`, `ip`,`keyword`, `long`, or `lookup`.
      Values: `boolean`, `composite`, `date`, `double`, `geo_point`, `geo_shape`, `ip`, `keyword`, `long`, `lookup`
  - `enabled` (boolean) — optional
  - `subobjects` (enum) — optional
    Values: `true`, `false`
  - `_data_stream_timestamp` (object) — optional
    - `enabled` (boolean) — required
- `settings` (object) — optional
  Configuration options for the index.

## Response

`application/json`

- `index` (string)
- `shards_acknowledged` (boolean)
- `acknowledged` (boolean)
## Code examples

#### Console

```console
PUT /my-index-000001
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 2
  }
}
```

#### JavaScript

```javascript
const response = await client.indices.create({
  index: "my-index-000001",
  settings: {
    number_of_shards: 3,
    number_of_replicas: 2,
  },
});
```

#### Python

```python
resp = client.indices.create(
    index="my-index-000001",
    settings={
        "number_of_shards": 3,
        "number_of_replicas": 2
    },
)
```

#### curl

```curl
curl -X PUT "$ELASTICSEARCH_URL/my-index-000001" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "settings": {
      "number_of_shards": 3,
      "number_of_replicas": 2
    }
  }'
```

#### Java

```java
client.indices().create(c -> c
    .index("my-index-000001")
    .settings(s -> s
        .otherSettings(Map.of())
        .numberOfShards("3")
        .numberOfReplicas("2")
    )
);
```

#### C#

```c#
var response = await client.Indices
    .CreateAsync(index: "my-index-000001", d1 => d1
        .Settings(d2 => d2
            .NumberOfReplicas(2)
            .NumberOfShards(3)
        )
    );
```

#### PHP

```php
$resp = $client->indices()->create([
    "index" => "my-index-000001",
    "body" => [
        "settings" => [
            "number_of_shards" => 3,
            "number_of_replicas" => 2,
        ],
    ],
]);
```

#### Ruby

```ruby
response = client.indices.create(
  index: "my-index-000001",
  body: {
    "settings": {
      "number_of_shards": 3,
      "number_of_replicas": 2
    }
  }
)
```

