0
0
Elasticsearchquery~10 mins

Partial updates in Elasticsearch - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to update the document with id '1' in the 'products' index using a partial update.

Elasticsearch
{
  "script": {
    "source": "ctx._source.price = [1]",
    "params": {
      "price": 20
    }
  }
}
Drag options to blanks, or click blank then click option'
Actx._price
Bprice
Cparams.price
Dctx.price
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'price' directly without 'params.' prefix
Trying to access 'ctx.price' which does not exist
2fill in blank
medium

Complete the code to update the 'stock' field by incrementing it by 5 using a script.

Elasticsearch
{
  "script": {
    "source": "ctx._source.stock [1]= 5"
  }
}
Drag options to blanks, or click blank then click option'
A*
B+
C-
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' which would decrement the value
Using '*' or '/' which would multiply or divide
3fill in blank
hard

Fix the error in the partial update to set the 'status' field to 'active'.

Elasticsearch
{
  "doc": {
    "status": [1]
  }
}
Drag options to blanks, or click blank then click option'
Astatus
B'active'
Cactive
D"active"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted active which is invalid JSON
Using single quotes which are not valid in JSON
4fill in blank
hard

Fill both blanks to create a partial update that adds a tag 'new' to the 'tags' array.

Elasticsearch
{
  "script": {
    "source": "ctx._source.tags.[1](params.tag)",
    "params": {
      "tag": [2]
    }
  }
}
Drag options to blanks, or click blank then click option'
Aadd
B"new"
Cappend
D'new'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'append' which is not valid in painless scripts
Using single quotes for strings
5fill in blank
hard

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.

Elasticsearch
{
  "script": {
    "source": "if (ctx._source.[1] [2] params.rating) { ctx._source.[3] = params.rating }",
    "params": {
      "rating": 4.5
    }
  }
}
Drag options to blanks, or click blank then click option'
Ascore
B<
Crating
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' in the condition
Using different field names for check and update