0
0
Elasticsearchquery~20 mins

Reindexing data in Elasticsearch - Practice Problems & Coding Challenges

Choose your learning style9 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.