# Use mustache syntax with update-by-query API

**URL:** <https://discuss.elastic.co/t/use-mustache-syntax-with-update-by-query-api/188331>\
**Category:** Elasticsearch\
**Created:** [July 1, 2019, 1:45pm UTC](https://discuss.elastic.co/t/use-mustache-syntax-with-update-by-query-api/188331 "2019-07-01T13:45:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aishwarya\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aishwarya_s/32/45312_2.png) [@Aishwarya\_S](https://discuss.elastic.co/u/Aishwarya_S)\
**Post date:** [July 1, 2019, 1:45pm UTC](https://discuss.elastic.co/t/use-mustache-syntax-with-update-by-query-api/188331/1 "2019-07-01T13:45:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 29, 2019, 1:45pm UTC](https://discuss.elastic.co/t/use-mustache-syntax-with-update-by-query-api/188331/2 "2019-07-29T13:45:59Z")

</div>

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