Bird
0
0

You want to increase the 'stock' field by 10 in a product document with ID '10' using a partial update. Which request body correctly achieves this?

hard🚀 Application Q15 of 15
Elasticsearch - Document Operations
You want to increase the 'stock' field by 10 in a product document with ID '10' using a partial update. Which request body correctly achieves this?
A{ "update": { "stock": 10 } }
B{ "doc": { "stock": 10 } }
C{ "doc": { "stock": "stock + 10" } }
D{ "script": { "source": "ctx._source.stock += params.count", "params": { "count": 10 } } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand increment operation in partial update

    To increase a numeric field, use a script that adds the value to the existing field.
  2. Step 2: Identify correct syntax for scripted update

    { "script": { "source": "ctx._source.stock += params.count", "params": { "count": 10 } } } uses the 'script' key with source code to add 10 to 'stock'.
  3. Final Answer:

    { "script": { "source": "ctx._source.stock += params.count", "params": { "count": 10 } } } -> Option D
  4. Quick Check:

    Use script to increment numeric fields [OK]
Quick Trick: Use script with ctx._source to increment fields [OK]
Common Mistakes:
MISTAKES
  • Trying to update with doc key using expression string
  • Using 'update' key instead of 'doc' or 'script'
  • Assigning value directly instead of incrementing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes