Bird
0
0

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🚀 Application Q15 of 15
Elasticsearch - Index Management

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?

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" } }
Step-by-Step Solution
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]
Quick Trick: Filter inside source; script adds fields during reindex [OK]
Common Mistakes:
MISTAKES
  • Placing query outside source object
  • Setting wrong value for new field
  • Using match instead of term for exact filter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes