elasticsearch,

How to create Elasticsearch index

Sep 02, 2021 · 1 min read · Post a comment

Creating an Elasticsearch index is a quick and easy process. In practice, there is an ELK API call that requires you to think of how many shards do you want to assign and replica shards as well. In this tutorial, I’m going to give you an overview of how can you achieve that.

Prerequisites

  • Elasticsearch cluster

Create Elasticsearch index

Create index elk_blogs:

PUT /elk_blogs
{
  "settings" : {
     "number_of_shards" : 3,
     "number_of_replicas" : 1
  }
}

By default, Elasticsearch will assign five primary shards if you don’t specify it. But, you can do it depending on your cluster capacity. In this example, I assigned three primary shards and one replica.

Get the Elasticsearch index

To get the info for the created Elasticsearch index, run:

GET /elk_blogs

Output:

...
"settings" : {
      "index" : {
        "number_of_shards" : "3",
        "provided_name" : "elk_blogs",
        "max_result_window" : "100000",
 ...
"number_of_replicas" : "1",
"uuid" : "nbDm4MRXQkSkJSKt9ejSEg",
...

Conclusion

From this tutorial, you can learn how to create an Elasticsearch index and get all the info about it. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.