Bird
0
0

You want to increase the stock field by 5 in a product document with ID 10. Which update request correctly does this?

hard🚀 Application Q15 of 15
Elasticsearch - Document Operations
You want to increase the stock field by 5 in a product document with ID 10. Which update request correctly does this?
APOST /products/_update/10 { "script": "ctx._source.stock += 5" }
BPOST /products/_update/10 { "doc": { "stock": "+5" } }
CPOST /products/_update/10 { "doc": { "stock": 5 } }
DPOST /products/_update/10 { "update": { "stock": 5 } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to increment a field

    To increase a numeric field, use a script that modifies the field value.
  2. Step 2: Analyze each option

    POST /products/_update/10 { "script": "ctx._source.stock += 5" } uses a script to add 5 to stock. Others either overwrite or use wrong syntax.
  3. Final Answer:

    POST /products/_update/10 { "script": "ctx._source.stock += 5" } -> Option A
  4. Quick Check:

    Use script to increment numeric fields [OK]
Quick Trick: Use script with ctx._source.field += value to increment [OK]
Common Mistakes:
MISTAKES
  • Trying to increment by setting doc field directly
  • Using incorrect JSON structure for update
  • Confusing doc and script usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes