📖 Scenario: You are setting up a simple search system for a small library. You want to create a place to store book information so you can find books easily later.
🎯 Goal: Create an Elasticsearch index called library with basic settings and mappings to store book titles and authors.
📋 What You'll Learn
Create an index named library
Add settings with number_of_shards set to 1
Add mappings for title and author fields as text
💡 Why This Matters
🌍 Real World
Creating an index is the first step in storing and searching data efficiently in Elasticsearch, useful for search engines, catalogs, and logs.
💼 Career
Knowing how to create and configure indexes is essential for roles like data engineer, backend developer, and search specialist working with Elasticsearch.
Progress0 / 4 steps
1
Create the index name
Write a JSON object to create an index named library with empty settings and mappings objects.
Elasticsearch
Hint
Start by naming the index library and add empty settings and mappings objects.
2
Add index settings
Add a settings object with number_of_shards set to 1 inside the index creation JSON.
Elasticsearch
Hint
Inside settings, set "number_of_shards" to 1 to keep it simple.
3
Add mappings for book fields
Add a mappings object with properties defining title and author fields as text type.
Elasticsearch
Hint
Inside mappings, add properties with title and author as text fields.
4
Complete the index creation JSON
Ensure the JSON object includes settings with number_of_shards set to 1, and mappings with title and author as text fields.
Elasticsearch
Hint
Double-check that all parts are included: settings, and mappings with correct fields.
Practice
(1/5)
1. What is the main purpose of creating an index in Elasticsearch?
easy
A. To encrypt data for security
B. To delete data permanently
C. To backup data automatically
D. To organize data for fast searching
Solution
Step 1: Understand the role of an index
An index in Elasticsearch is like a folder that organizes documents to make searching fast and efficient.
Step 2: Compare options with index purpose
Deleting, backing up, or encrypting data are not the main functions of an index.
Final Answer:
To organize data for fast searching -> Option D
Quick Check:
Index = Organize data for search [OK]
Hint: Index means organizing data for quick search [OK]
Common Mistakes:
Confusing index with backup or encryption
Thinking index deletes data
Assuming index automatically secures data
2. Which is the correct syntax to create an index named products in Elasticsearch?
easy
A. PUT /products
B. POST /products
C. GET /products
D. DELETE /products
Solution
Step 1: Recall HTTP methods for index creation
Elasticsearch uses the PUT method to create an index with a specific name.
Step 2: Match method with index name
PUT /products correctly creates the index named 'products'. POST is used for adding documents, GET for retrieving, DELETE for removing.