Use mustache syntax with update-by-query API

Hi All,

I am trying to use Mustache syntax in _update_by_query API. Basically I want to find a document in Elasticsearch and apply a script on the document returned and update it.

I am first creating the script as specified below:

I have some data created under an index "products":

PUT products/sampleproducts/1
{
  "name": "sample1",
  "id":"1",
  "price":"60"
}

I am now creating a script which will later be used in the _update_by_query API.

POST _scripts/products-price-multiplier
{
  "script": {
    "lang": "painless",
    "source": "Math.log(price * 2) + params.my_modifier"
  }
}

I want to use the script created above in _update_by_query API by providing the script id i.e "products-price-multiplier":

POST products/sampleproducts/_update_by_query
{
 "id":"products-price-multiplier",
 "query": {
   "term": {
     "price" : "60"
   }
 },
 "params": {
   "my_modifier": 2
 }
}

I am getting an exception saying "id" cannot be recognized.

I have the following questions based on my observations described above:

  1. Is it possible to use Mustache syntax in _update_by_query API or can it be used only in _search/template based requests?

  2. If its possible, how exactly it needs to be done?

3.And what is the difference between a _bulk update and _update_by_query API? Does _update_by_query use bulk API under the hood? Which of them is better in performance?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.