Bird
0
0

You want to reindex data from products_old to products_new and rename the field price to cost during reindexing. Which script correctly performs this transformation?

hard🚀 Application Q9 of 15
Elasticsearch - Index Management

You want to reindex data from products_old to products_new and rename the field price to cost during reindexing. Which script correctly performs this transformation?

A{ "source": { "index": "products_old" }, "dest": { "index": "products_new" }, "script": { "source": "ctx._source.cost = ctx._source.remove('price')" } }
B{ "source": { "index": "products_old" }, "dest": { "index": "products_new" }, "script": { "source": "ctx._source.price = ctx._source.cost" } }
C{ "source": { "index": "products_old" }, "dest": { "index": "products_new" }, "script": { "source": "ctx._source.cost = ctx._source.price" } }
D{ "source": { "index": "products_old" }, "dest": { "index": "products_new" }, "script": { "source": "ctx._source.price = ctx._source.remove('cost')" } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand field renaming

    To rename a field, assign the old field's value to the new field and remove the old field.
  2. Step 2: Analyze scripts

    { "source": { "index": "products_old" }, "dest": { "index": "products_new" }, "script": { "source": "ctx._source.cost = ctx._source.remove('price')" } } assigns cost from price and removes price, correctly renaming it.
  3. Step 3: Eliminate incorrect options

    { "source": { "index": "products_old" }, "dest": { "index": "products_new" }, "script": { "source": "ctx._source.price = ctx._source.cost" } } copies cost from price incorrectly. { "source": { "index": "products_old" }, "dest": { "index": "products_new" }, "script": { "source": "ctx._source.cost = ctx._source.price" } } copies price to cost but does not remove price. { "source": { "index": "products_old" }, "dest": { "index": "products_new" }, "script": { "source": "ctx._source.price = ctx._source.remove('cost')" } } incorrectly removes cost.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Assign new field and remove old field [OK]
Quick Trick: Assign new field and remove old field to rename [OK]
Common Mistakes:
MISTAKES
  • Not removing the old field after copying
  • Assigning fields in wrong direction
  • Removing the wrong field

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes