Bird
Raised Fist0
Elasticsearchquery~20 mins

Reindexing data in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Elasticsearch Reindexing Master
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 reindexing task response?

Given the following Elasticsearch reindex API request, what will be the value of response['created'] after the task completes successfully?

Elasticsearch
{
  "source": {"index": "old_index"},
  "dest": {"index": "new_index"}
}

// Assume old_index has 100 documents and no errors occur.
A0
BAn error is thrown
C100
Dnull
Attempts:
2 left
💡 Hint

Reindexing copies documents from source to destination. The created field shows how many documents were added.

🧠 Conceptual
intermediate
1:30remaining
Which option correctly describes the purpose of the 'wait_for_completion' parameter in Elasticsearch reindex API?

What does setting wait_for_completion to false do when running a reindex task?

AWaits for the reindex task to finish before returning the response.
BRuns the reindex task asynchronously and returns a task ID immediately.
CCancels the reindex task immediately.
DRuns the reindex task only if the destination index exists.
Attempts:
2 left
💡 Hint

Think about how asynchronous tasks work in Elasticsearch.

🔧 Debug
advanced
2:30remaining
Why does this reindex request fail with a 'version_conflict_engine_exception' error?

Consider this reindex request:

{
  "source": {"index": "source_index"},
  "dest": {"index": "dest_index", "op_type": "create"}
}

Both indices have documents with overlapping IDs. What causes the error?

ABecause <code>op_type: create</code> forbids overwriting existing documents, causing conflicts on duplicate IDs.
BBecause the source index is empty.
CBecause the destination index does not exist.
DBecause the reindex API does not support <code>op_type</code> parameter.
Attempts:
2 left
💡 Hint

Check what op_type: create means in Elasticsearch indexing.

📝 Syntax
advanced
2:00remaining
Which option is the correct syntax to reindex documents with a script that adds a new field 'status' with value 'archived'?

Choose the valid reindex request that adds a new field status with value archived to each document.

A
{
  "source": {"index": "old_index"},
  "dest": {"index": "new_index"},
  "script": {
    "source": "ctx._source.status = 'archived'"
  }
}
B
{
  "source": {"index": "old_index"},
  "dest": {"index": "new_index"},
  "script": "ctx._source.status = 'archived'"
}
C
{
  "source": {"index": "old_index"},
  "dest": {"index": "new_index"},
  "script": {
    "inline": "ctx._source.status = 'archived'"
  }
}
D
{
  "source": {"index": "old_index"},
  "dest": {"index": "new_index"},
  "script": {
    "code": "ctx._source.status = 'archived'"
  }
}
Attempts:
2 left
💡 Hint

Check the correct key for the script source in Elasticsearch reindex API.

🚀 Application
expert
3:00remaining
How to reindex only documents where 'status' is 'active' and update 'last_updated' field to current date?

You want to reindex documents from users index to users_archive index. Only documents with status equal to active should be copied. Also, add or update a field last_updated with the current date during reindexing.

Which request accomplishes this?

A
{
  "source": {
    "index": "users",
    "query": { "term": { "status": "active" } }
  },
  "dest": {"index": "users_archive"},
  "script": {
    "source": "ctx._source.last_updated = params.now",
    "params": {"now": "{{ctx.execution_time}}"}
  }
}
B
{
  "source": {
    "index": "users",
    "query": { "match": { "status": "active" } }
  },
  "dest": {"index": "users_archive"},
  "script": {
    "source": "ctx._source.last_updated = new Date()"
  }
}
C
{
  "source": {
    "index": "users",
    "query": { "term": { "status": "active" } }
  },
  "dest": {"index": "users_archive"},
  "script": {
    "source": "ctx._source.last_updated = params.now",
    "params": {"now": "2024-01-01T00:00:00Z"}
  }
}
D
{
  "source": {
    "index": "users",
    "query": { "term": { "status": "active" } }
  },
  "dest": {"index": "users_archive"},
  "script": {
    "source": "ctx._source.last_updated = Instant.now()"
  }
}
Attempts:
2 left
💡 Hint

Painless scripts support Instant.now() for current time. Avoid JavaScript-like syntax or invalid placeholders.

Practice

(1/5)
1.

What is the main purpose of _reindex API in Elasticsearch?

easy
A. To delete an index permanently
B. To copy data from one index to another
C. To update the Elasticsearch cluster settings
D. To create a new index with default settings

Solution

  1. Step 1: Understand the function of _reindex

    The _reindex API is designed to copy documents from a source index to a destination index.
  2. Step 2: Differentiate from other operations

    Deleting an index, updating cluster settings, or creating new indexes are different APIs and not the purpose of _reindex.
  3. Final Answer:

    To copy data from one index to another -> Option B
  4. Quick Check:

    _reindex copies data [OK]
Hint: Remember: reindex means copying data between indexes [OK]
Common Mistakes:
  • Confusing reindex with deleting indexes
  • Thinking reindex updates cluster settings
  • Assuming reindex creates new indexes without data
2.

Which of the following is the correct minimal syntax to reindex data from old_index to new_index using Elasticsearch's REST API?

{
  "source": {"index": "old_index"},
  "dest": {"index": "new_index"}
}
easy
A. { "source": { "index": "old_index" }, "dest": { "index": "new_index" } }
B. { "source": { "index": "new_index" }, "dest": { "index": "old_index" } }
C. { "source": { "index": "old_index" }, "destination": { "index": "new_index" } }
D. { "src": { "index": "old_index" }, "dest": { "index": "new_index" } }

Solution

  1. Step 1: Check the required keys for reindex

    The correct keys are source and dest with nested index names.
  2. Step 2: Validate the index names and key spelling

    { "source": { "index": "old_index" }, "dest": { "index": "new_index" } } uses correct keys and index names. { "source": { "index": "new_index" }, "dest": { "index": "old_index" } } swaps source and destination incorrectly. { "source": { "index": "old_index" }, "destination": { "index": "new_index" } } uses wrong key destination. { "src": { "index": "old_index" }, "dest": { "index": "new_index" } } uses wrong key src.
  3. Final Answer:

    { "source": { "index": "old_index" }, "dest": { "index": "new_index" } } -> Option A
  4. Quick Check:

    Use source and dest keys exactly [OK]
Hint: Use exact keys: source and dest for reindex JSON [OK]
Common Mistakes:
  • Swapping source and destination indexes
  • Using wrong keys like 'src' or 'destination'
  • Misspelling 'dest' or 'source'
3.

Given the following reindex request, what will be the result?

{
  "source": { "index": "products" },
  "dest": { "index": "products_new" },
  "script": {
    "source": "ctx._source.price = ctx._source.price * 1.1"
  }
}

Assuming products has documents with a price field.

medium
A. Only documents with price > 1.1 are copied
B. Documents copied without any price change
C. Reindex fails due to script syntax error
D. All documents copied with price increased by 10%

Solution

  1. Step 1: Understand the script in reindex

    The script modifies each document's price by multiplying it by 1.1 during reindexing.
  2. Step 2: Effect on documents

    All documents from products are copied to products_new with updated price values increased by 10%.
  3. Final Answer:

    All documents copied with price increased by 10% -> Option D
  4. Quick Check:

    Script modifies price during reindex [OK]
Hint: Scripts can modify fields during reindexing [OK]
Common Mistakes:
  • Assuming script filters documents instead of modifying
  • Thinking script causes syntax error
  • Believing price remains unchanged
4.

Identify the error in this reindex request:

{
  "source": { "index": "old_index" },
  "dest": { "index": "new_index" },
  "query": {
    "match": { "status": "active" }
  }
}
medium
A. The query should be inside the "source" object
B. "query" is not allowed inside reindex requests
C. The "match" syntax is incorrect
D. The "dest" index name cannot be "new_index"

Solution

  1. Step 1: Check placement of query in reindex

    The query must be inside the source object to filter documents.
  2. Step 2: Validate other parts

    The match syntax is correct, and dest index name is valid.
  3. Final Answer:

    The query should be inside the "source" object -> Option A
  4. Quick Check:

    Put query inside source to filter during reindex [OK]
Hint: Put filters inside source, not at top level [OK]
Common Mistakes:
  • Placing query outside source object
  • Misunderstanding match query syntax
  • Thinking destination index name is invalid
5.

You want to reindex data from logs_2023 to logs_archive but only include documents where level is "error" and add a new field archived set to true. Which reindex request achieves this?

hard
A. { "source": { "index": "logs_2023", "query": { "match": { "level": "error" } } }, "dest": { "index": "logs_archive" }, "script": { "source": "ctx._source.archived = false" } }
B. { "source": { "index": "logs_2023" }, "dest": { "index": "logs_archive" }, "query": { "term": { "level": "error" } }, "script": { "source": "ctx._source.archived = true" } }
C. { "source": { "index": "logs_2023", "query": { "term": { "level": "error" } } }, "dest": { "index": "logs_archive" }, "script": { "source": "ctx._source.archived = true" } }
D. { "source": { "index": "logs_2023", "query": { "term": { "level": "error" } } }, "dest": { "index": "logs_archive" }, "script": { "source": "ctx._source.archived = false" } }

Solution

  1. Step 1: Filter documents by level "error" inside source

    The query with term filter must be inside the source object to select only error level logs.
  2. Step 2: Add new field "archived" with value true via script

    The script sets ctx._source.archived = true to add the new field during reindex.
  3. Step 3: Validate requests

    The request that places query inside source with term filter for level: "error" and script setting ctx._source.archived = true is correct. Placing query at top level is invalid. Using match instead of term or setting archived to false is incorrect.
  4. Final Answer:

    { "source": { "index": "logs_2023", "query": { "term": { "level": "error" } } }, "dest": { "index": "logs_archive" }, "script": { "source": "ctx._source.archived = true" } } -> Option C
  5. Quick Check:

    Filter in source + script sets field true [OK]
Hint: Filter inside source; script adds fields during reindex [OK]
Common Mistakes:
  • Placing query outside source object
  • Setting wrong value for new field
  • Using match instead of term for exact filter
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