# Is there a way to use update by query in template?

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-use-update-by-query-in-template/190681>\
**Category:** Elasticsearch\
**Created:** [July 16, 2019, 8:26am UTC](https://discuss.elastic.co/t/is-there-a-way-to-use-update-by-query-in-template/190681 "2019-07-16T08:26:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fahad\_Khan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fahad_khan/32/42682_2.png) [@Fahad\_Khan](https://discuss.elastic.co/u/Fahad_Khan)\
**Post date:** [July 16, 2019, 8:26am UTC](https://discuss.elastic.co/t/is-there-a-way-to-use-update-by-query-in-template/190681/1 "2019-07-16T08:26:15Z")

</div>

Hi,  
I want to create a template which will take user's value and will search against those values and update those returned documents which matched the user given condition. plz see the following

```
POST _scripts/<template name>
{
    "script": {
        "lang": "mustache",
        "source": {
  "query":{  
        "multi_match" :{
          "query": "{{Sender/cc/bcc/to}}",
          "fields": ["from","to","cc","bcc"]
   } }
  }     
  },
  "script" : "ctx._source.lebel_id = {{label_id}}; ctx.source.case_id={{case_id }}"
  }
GET /_search/template
{
    "id":"<template name>", 
    "params": {
        "Sender/cc/bcc/to": "jm@bloomberg.net",
        "case_id": 10,
       "labe_id": 12
    }
}

```

Is it possible to do it in one query?

---

<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:** [August 13, 2019, 8:26am UTC](https://discuss.elastic.co/t/is-there-a-way-to-use-update-by-query-in-template/190681/2 "2019-08-13T08:26:17Z")

</div>

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