Bird
Raised Fist0
Elasticsearchquery~20 mins

Creating an index in Elasticsearch - Practice Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Elasticsearch Index Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
What is the output of this index creation request?

Given the following Elasticsearch request to create an index named library with a simple mapping, what will be the response status?

Elasticsearch
{
  "mappings": {
    "properties": {
      "title": { "type": "text" },
      "author": { "type": "keyword" },
      "year": { "type": "integer" }
    }
  }
}
A{"acknowledged":true,"shards_acknowledged":true,"index":"library"}
B{"error":"index_already_exists_exception","status":400}
C{"acknowledged":false,"shards_acknowledged":false,"index":"library"}
D{"error":"illegal_argument_exception","status":400}
Attempts:
2 left
💡 Hint

Successful index creation returns acknowledged: true.

🧠 Conceptual
intermediate
1:30remaining
Which setting controls the number of primary shards when creating an index?

When creating an Elasticsearch index, which setting defines how many primary shards the index will have?

A"number_of_replicas"
B"refresh_interval"
C"index_buffer_size"
D"number_of_shards"
Attempts:
2 left
💡 Hint

Think about how data is split across the cluster.

📝 Syntax
advanced
2:30remaining
Which JSON snippet correctly creates an index with 3 replicas?

Select the correct JSON body to create an Elasticsearch index named products with 1 primary shard and 3 replicas.

A
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 3
  }
}
B
{
  "settings": {
    "shards": 1,
    "replicas": 3
  }
}
C
{
  "settings": {
    "number_of_shards": "1",
    "number_of_replicas": "3"
  }
}
D
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1
  }
}
Attempts:
2 left
💡 Hint

Settings keys must be exact and values numeric, not strings.

🔧 Debug
advanced
2:00remaining
Why does this index creation fail?

Consider this request to create an index named users with a mapping:

{
  "mappings": {
    "properties": {
      "name": { "type": "text" },
      "age": { "type": "integer" },
      "email": { "type": "keyword" }
    }
  },
  "settings": {
    "number_of_shards": 0
  }
}

Why will this request fail?

ABecause <code>mappings</code> must be inside <code>settings</code>
BBecause <code>integer</code> type is not allowed in mappings
CBecause <code>number_of_shards</code> cannot be zero; it must be at least 1
DBecause <code>keyword</code> type is invalid for <code>email</code>
Attempts:
2 left
💡 Hint

Think about shard count limits.

❓ optimization
expert
3:00remaining
Which index setting improves search speed by disabling _source storage?

You want to optimize an Elasticsearch index for search speed and reduce storage size. Which setting disables storing the original JSON document and can improve performance?

A"store": { "enabled": false }
B"_source": { "enabled": false }
C"index.store.type": "none"
D"refresh_interval": "-1"
Attempts:
2 left
💡 Hint

The original JSON document is stored in a special field called _source.

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

  1. 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.
  2. Step 2: Compare options with index purpose

    Deleting, backing up, or encrypting data are not the main functions of an index.
  3. Final Answer:

    To organize data for fast searching -> Option D
  4. 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

  1. Step 1: Recall HTTP methods for index creation

    Elasticsearch uses the PUT method to create an index with a specific name.
  2. 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.
  3. Final Answer:

    PUT /products -> Option A
  4. Quick Check:

    PUT creates index [OK]
Hint: Use PUT to create an index by name [OK]
Common Mistakes:
  • Using POST instead of PUT for index creation
  • Confusing GET with creation
  • Trying DELETE to create index
3. Given this request to create an index:
{
  "settings": {"number_of_shards": 1},
  "mappings": {
    "properties": {
      "name": {"type": "text"},
      "price": {"type": "float"}
    }
  }
}

What will be the type of the price field in the index?
medium
A. keyword
B. float
C. integer
D. text

Solution

  1. Step 1: Read the mapping for the price field

    The mapping defines "price" with "type": "float" which means it stores decimal numbers.
  2. Step 2: Understand field types

    Float is a number with decimals, integer is whole number, text is for full text search, keyword is for exact matches.
  3. Final Answer:

    float -> Option B
  4. Quick Check:

    price type = float [OK]
Hint: Check mapping 'type' for field data type [OK]
Common Mistakes:
  • Confusing float with integer
  • Assuming text type for numbers
  • Mixing keyword with numeric types
4. Identify the error in this index creation request:
PUT /library
{
  "settings": {
    "number_of_shards": "two"
  },
  "mappings": {
    "properties": {
      "title": {"type": "text"}
    }
  }
}
medium
A. number_of_shards should be a number, not a string
B. title field type should be keyword, not text
C. PUT method cannot be used to create index
D. Missing index name in URL

Solution

  1. Step 1: Check the settings syntax

    number_of_shards must be a numeric value, but "two" is a string, causing an error.
  2. Step 2: Validate other parts

    Field type 'text' is valid for title, PUT is correct method, index name 'library' is present.
  3. Final Answer:

    number_of_shards should be a number, not a string -> Option A
  4. Quick Check:

    number_of_shards = number [OK]
Hint: Settings values must match expected data types [OK]
Common Mistakes:
  • Using string instead of number for shards
  • Confusing field types for text fields
  • Using wrong HTTP method for index creation
5. You want to create an index users with a field age that should only accept whole numbers and be searchable. Which mapping is correct?
hard
A. { "mappings": { "properties": { "age": { "type": "float" } } } }
B. { "mappings": { "properties": { "age": { "type": "text" } } } }
C. { "mappings": { "properties": { "age": { "type": "integer" } } } }
D. { "mappings": { "properties": { "age": { "type": "keyword" } } } }

Solution

  1. Step 1: Understand the data type needed for age

    Age is a whole number, so integer type is appropriate to store numeric whole values.
  2. Step 2: Check searchability and field types

    Text is for full text search, float allows decimals, keyword is for exact matches but not numeric operations.
  3. Final Answer:

    { "mappings": { "properties": { "age": { "type": "integer" } } } } -> Option C
  4. Quick Check:

    Whole number field = integer type [OK]
Hint: Use integer type for whole number searchable fields [OK]
Common Mistakes:
  • Using text type for numeric fields
  • Choosing float when decimals not needed
  • Using keyword for numeric data
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard