Bird
Raised Fist0
Elasticsearchquery~20 mins

Document ID strategies (auto vs manual) in Elasticsearch - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Document ID Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this Elasticsearch indexing operation with manual ID?

Consider this Elasticsearch indexing request using a manual document ID:

{
  "index": "products",
  "id": "12345",
  "body": {
    "name": "Laptop",
    "price": 1200
  }
}

What will be the result if you try to index the same document with the same ID again but with a different price?

Elasticsearch
POST /products/_doc/12345
{
  "name": "Laptop",
  "price": 1300
}
AThe document with ID '12345' will be updated with the new price 1300.
BElasticsearch will create a new document with a different ID automatically.
CAn error will occur because the ID '12345' already exists.
DThe original document will remain unchanged and the new document will be rejected silently.
Attempts:
2 left
💡 Hint

Think about how Elasticsearch handles indexing with the same manual ID.

❓ Predict Output
intermediate
2:00remaining
What happens when you index documents without specifying an ID?

Given this indexing request without specifying an ID:

POST /orders/_doc
{
  "order_id": "A001",
  "amount": 250
}

What will Elasticsearch do?

Elasticsearch
POST /orders/_doc
{
  "order_id": "A001",
  "amount": 250
}
AThe document will be rejected because ID is missing.
BThe document will be indexed with 'order_id' as the ID automatically.
CAn error will occur because the ID field is required in the body.
DElasticsearch will generate a unique ID automatically for the document.
Attempts:
2 left
💡 Hint

Think about the default behavior when no ID is provided.

🧠 Conceptual
advanced
2:00remaining
Which is a key advantage of using manual document IDs in Elasticsearch?

Choose the main advantage of assigning manual IDs to documents instead of letting Elasticsearch generate them automatically.

AIt improves Elasticsearch's internal indexing speed significantly.
BIt allows easy updates and overwrites of documents by referencing the same ID.
CIt guarantees that documents will never be deleted accidentally.
DIt automatically prevents duplicate documents with the same content.
Attempts:
2 left
💡 Hint

Think about how manual IDs help with document management.

❓ Predict Output
advanced
2:00remaining
What error occurs when indexing with an invalid ID format?

Consider this indexing request with an invalid ID containing spaces:

POST /users/_doc/invalid%20id
{
  "name": "Alice"
}

What error will Elasticsearch return?

Elasticsearch
POST /users/_doc/invalid%20id
{
  "name": "Alice"
}
A500 Internal Server Error due to server crash.
BDocument indexed successfully with ID 'invalid id'.
C400 Bad Request with error about invalid ID format.
D404 Not Found because the index does not exist.
Attempts:
2 left
💡 Hint

Think about allowed characters in Elasticsearch document IDs.

🧠 Conceptual
expert
2:00remaining
Why might auto-generated IDs cause performance issues in Elasticsearch?

Choose the best explanation why using auto-generated document IDs can sometimes reduce indexing performance.

ABecause auto-generated IDs are random, they cause frequent shard relocations and reduce cache efficiency.
BBecause auto-generated IDs are sequential, they cause index fragmentation.
CBecause auto-generated IDs prevent Elasticsearch from compressing stored data.
DBecause auto-generated IDs require manual conflict resolution by the user.
Attempts:
2 left
💡 Hint

Think about how random IDs affect data distribution in shards.

Practice

(1/5)
1. What is the main difference between automatic and manual document IDs in Elasticsearch?
easy
A. Automatic IDs are generated by Elasticsearch; manual IDs are set by the user.
B. Automatic IDs require user input; manual IDs are generated by Elasticsearch.
C. Automatic IDs are always numeric; manual IDs are always strings.
D. Automatic IDs cannot be used for updates; manual IDs cannot.

Solution

  1. Step 1: Understand automatic ID generation

    Elasticsearch creates unique IDs automatically when you don't specify one.
  2. Step 2: Understand manual ID assignment

    Users can assign their own IDs to documents for control and easier updates.
  3. Final Answer:

    Automatic IDs are generated by Elasticsearch; manual IDs are set by the user. -> Option A
  4. Quick Check:

    Auto = Elasticsearch generated, Manual = user set [OK]
Hint: Auto = system creates ID, manual = you create ID [OK]
Common Mistakes:
  • Confusing which side creates the ID
  • Thinking automatic IDs are numeric only
  • Believing manual IDs cannot be updated
2. Which of the following is the correct syntax to index a document with a manual ID in Elasticsearch using JSON?
easy
A. { "index": "my_index", "_id": "123", "body": { "name": "Alice" } }
B. { "index": "my_index", "id": "123", "body": { "name": "Alice" } }
C. { "index": "my_index", "id": 123, "doc": { "name": "Alice" } }
D. { "index": "my_index", "_id": 123, "doc": { "name": "Alice" } }

Solution

  1. Step 1: Identify the correct field for manual ID

    Elasticsearch uses "_id" (with underscore) to specify manual document IDs.
  2. Step 2: Check the correct structure for indexing

    The "body" key holds the document content; "doc" is used for updates, not indexing.
  3. Final Answer:

    { "index": "my_index", "_id": "123", "body": { "name": "Alice" } } -> Option A
  4. Quick Check:

    Manual ID uses "_id" and "body" for document [OK]
Hint: Use "_id" for manual IDs and "body" for document content [OK]
Common Mistakes:
  • Using "id" instead of "_id"
  • Confusing "doc" with "body" for indexing
  • Passing numeric ID without quotes
3. Given this indexing request with manual ID:
{ "index": "products", "_id": "p100", "body": { "name": "Pen", "price": 1.5 } }

What happens if you send the same request again with updated price 1.8?
medium
A. A new document is created with a different ID.
B. The existing document with ID "p100" is updated with the new price.
C. An error occurs because duplicate IDs are not allowed.
D. The document is ignored and no changes happen.

Solution

  1. Step 1: Understand manual ID behavior on indexing

    Using the same manual ID overwrites the existing document with that ID.
  2. Step 2: Check the effect of sending updated data

    The document with ID "p100" will be updated to have price 1.8.
  3. Final Answer:

    The existing document with ID "p100" is updated with the new price. -> Option B
  4. Quick Check:

    Same manual ID means update existing document [OK]
Hint: Same manual ID updates document, no new doc created [OK]
Common Mistakes:
  • Thinking a new document is created with same ID
  • Expecting an error on duplicate ID
  • Assuming no change happens on reindex
4. You tried to index a document with this JSON:
{ "index": "users", "id": "u123", "body": { "name": "Bob" } }

But the document was not saved with ID "u123". What is the likely problem?
medium
A. The "body" field is missing required fields.
B. The index name "users" is invalid.
C. The field "id" should be "_id" to set manual ID.
D. Manual IDs are not allowed in Elasticsearch.

Solution

  1. Step 1: Check the ID field name

    Elasticsearch requires "_id" (with underscore) to specify manual IDs, not "id".
  2. Step 2: Confirm impact of wrong field

    Using "id" means Elasticsearch ignores it and generates an automatic ID instead.
  3. Final Answer:

    The field "id" should be "_id" to set manual ID. -> Option C
  4. Quick Check:

    Manual ID needs "_id", not "id" [OK]
Hint: Use "_id" to set manual ID, not "id" [OK]
Common Mistakes:
  • Using "id" instead of "_id"
  • Assuming missing fields cause ID issues
  • Thinking manual IDs are disallowed
5. You want to avoid duplicate documents in Elasticsearch. Which strategy can help you achieve this?
hard
A. Use a random string as manual ID without relation to document content.
B. Always use automatic IDs and ignore duplicates.
C. Index documents without IDs and rely on timestamps to find duplicates.
D. Use a manual ID based on a unique field like email to prevent duplicates.

Solution

  1. Step 1: Understand duplicate prevention

    Duplicates can be avoided by assigning manual IDs based on unique fields like email.
  2. Step 2: Compare with automatic ID approach

    Automatic IDs are random and do not prevent duplicates because each document gets a new ID.
  3. Final Answer:

    Use a manual ID based on a unique field like email to prevent duplicates. -> Option D
  4. Quick Check:

    Manual unique IDs prevent duplicates, auto IDs do not [OK]
Hint: Manual unique IDs prevent duplicates better than auto IDs [OK]
Common Mistakes:
  • Thinking auto IDs prevent duplicates
  • Using random manual IDs unrelated to content
  • Relying on timestamps instead of IDs
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