Complete the code to update the document with id '1' in the 'products' index using a partial update.
{
"script": {
"source": "ctx._source.price = [1]",
"params": {
"price": 20
}
}
}The script uses params.price to access the parameter passed for the update.
Complete the code to update the 'stock' field by incrementing it by 5 using a script.
{
"script": {
"source": "ctx._source.stock [1]= 5"
}
}The operator += increments the 'stock' field by 5.
Fix the error in the partial update to set the 'status' field to 'active'.
{
"doc": {
"status": [1]
}
}String values in JSON must be enclosed in double quotes, so use "active".
Fill both blanks to create a partial update that adds a tag 'new' to the 'tags' array.
{
"script": {
"source": "ctx._source.tags.[1](params.tag)",
"params": {
"tag": [2]
}
}
}The method to add an element to an array is add, and the tag string must be double quoted "new".
Fill all three blanks to create a partial update that sets 'rating' to 4.5 only if the current rating is less than 4.5.
{
"script": {
"source": "if (ctx._source.[1] [2] params.rating) { ctx._source.[3] = params.rating }",
"params": {
"rating": 4.5
}
}
}The field to check and update is 'rating'. The condition uses '<' to check if current rating is less than 4.5.