AI Hints
Home›Elasticsearch Tutorial›Indexes and Documents
Elasticsearch · Lesson 10 of 120

Creating an Index

Settings first.

⏱ 2 min read▶ Video at 9:11🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

Elasticsearch can create an index for you, but in real projects you create it yourself. That way you choose its settings, like how many shards and replicas it has.

  • Auto works
  • Better: create it
  • Choose settings

PUT an index

PUT, then the index name, creates an index. In settings, we ask for one shard. And zero replicas, because we only have one node. Run it. Acknowledged true means the index exists.

Dev Tools Consoletext
PUT products
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}
Output
{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "products"
}

See its settings

GET products, slash settings, shows the settings back. Run it. One shard, and zero replicas. Index names must be lower case, and can't contain spaces.

Dev Tools Consoletext
GET products/_settings?filter_path=*.settings.index.number_of_*,*.settings.index.provided_name
Output
{
  "products": {
    "settings": {
      "index": {
        "number_of_shards": "1",
        "provided_name": "products",
        "number_of_replicas": "0"
      }
    }
  }
}
Also uses _setup.http
PUT products
{ "settings": { "number_of_shards": 1, "number_of_replicas": 0 } }

Summary

PUT with a name creates an index, and settings choose its shards and replicas. Next, putting documents into it.

Key takeaways
  • PUT products
  • Shards
  • Replicas
Next up: Indexing a Document — PUT with an ID