# How can we update multiple documents using callwithrequest

**URL:** <https://discuss.elastic.co/t/how-can-we-update-multiple-documents-using-callwithrequest/187578>\
**Category:** Kibana\
**Created:** [June 26, 2019, 1:34pm UTC](https://discuss.elastic.co/t/how-can-we-update-multiple-documents-using-callwithrequest/187578 "2019-06-26T13:34:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![adityaPsl](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@adityaPsl](https://discuss.elastic.co/u/adityaPsl)\
**Post date:** [June 26, 2019, 1:34pm UTC](https://discuss.elastic.co/t/how-can-we-update-multiple-documents-using-callwithrequest/187578/1 "2019-06-26T13:34:51Z")

</div>

Hello Team,

I am working on a use case where I need to update multiple documents.

I have created a custom Kibana plugin and I am able to update single document using callwithrequest by passing document.

Could you please help me understand how can I update multiple documents in single API call.

Thanks for your help and support.  
Kibana version : 6.7

Thank you,  
Aditya

---

<div class="post-metadata">

**Author:** ![mattkime](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattkime/32/43522_2.png) [@mattkime](https://discuss.elastic.co/u/mattkime)\
**Post date:** [June 26, 2019, 8:14pm UTC](https://discuss.elastic.co/t/how-can-we-update-multiple-documents-using-callwithrequest/187578/2 "2019-06-26T20:14:21Z")

</div>

Would the Update By Query elasticsearch API work for you? [https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html)

---

<div class="post-metadata">

**Author:** ![adityaPsl](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@adityaPsl](https://discuss.elastic.co/u/adityaPsl)\
**Post date:** [June 30, 2019, 2:26am UTC](https://discuss.elastic.co/t/how-can-we-update-multiple-documents-using-callwithrequest/187578/3 "2019-06-30T02:26:56Z")

</div>

Thank you Matthew,  
Sorry for the delayed response.  
I was checking this update by query but i could not find a way to update documents having id equal to the list of ids.  
for example  
update field='some value' where id in []  
i am using EUIBasicTable select option to get the list of ids.

Thank you,  
Aditya

---

<div class="post-metadata">

**Author:** ![iukea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iukea/32/49083_2.png) [@iukea](https://discuss.elastic.co/u/iukea)\
**Post date:** [June 30, 2019, 3:14am UTC](https://discuss.elastic.co/t/how-can-we-update-multiple-documents-using-callwithrequest/187578/4 "2019-06-30T03:14:21Z")

</div>

l don't know if this is what you are looking for but this will update fields and their values throughout your indexes or index.

```
  POST logstash-*/_update_by_query
    {
      "script": {
        "source": "ctx._source.type='ChangeMeOld'",
        "lang": "painless"
      },
      "query": {
        "term": {
          "type.keyword": "changeMeNEW"
        }
      }
    }
```

---

<div class="post-metadata">

**Author:** ![Juanma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/juanma/32/49076_2.png) [@Juanma](https://discuss.elastic.co/u/Juanma)\
**Post date:** [June 30, 2019, 11:47am UTC](https://discuss.elastic.co/t/how-can-we-update-multiple-documents-using-callwithrequest/187578/5 "2019-06-30T11:47:48Z")

</div>

Hello @adityaPsl

As @mattkime said I think that what you seek is the update by query.

For update a given field for example update\_field of a list of ids you could use the following REST api call:

```
POST index-name/_update_by_query
{
  "script":{
    "source":"ctx._source.update_field='some value'",
    "lang":"painless"
  },
  "query": {
    "terms": {
      "_id": [
        "id1",
        "id2",
        "so on.."
      ]
    }
  }
}

```

As you can see it will update the "update\_field to "some\_value" in all the documents matching the terms query where \_id is on the list.

If the list of the \_ids is huge you also can add _?wait\_for\_completion=false_ to the rest call and it will give you back an id which you can track with \_tasks API as follows:

```
GET _tasks/ID_RETRIEVED_BY_API 

```

You can check the \_tasks api here [https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html)

I hope this help. 🙂

---

<div class="post-metadata">

**Author:** ![adityaPsl](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@adityaPsl](https://discuss.elastic.co/u/adityaPsl)\
**Post date:** [July 5, 2019, 10:01am UTC](https://discuss.elastic.co/t/how-can-we-update-multiple-documents-using-callwithrequest/187578/6 "2019-07-05T10:01:41Z")

</div>

Hi Juanma,

Thank you very much for your response.  
Sorry for the delay,  
I am trying to achieve this functionality from custom plugin using callwithrequest.  
I am getting invalid endpoint error for  
\_update\_by\_query also tried update\_by\_query and updatebyquery.

Any pointers or documentation links to resolve the issue would really help.

Thank you for your help and support.

Thank you,  
Aditya

---

<div class="post-metadata">

**Author:** ![adityaPsl](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@adityaPsl](https://discuss.elastic.co/u/adityaPsl)\
**Post date:** [July 19, 2019, 5:21pm UTC](https://discuss.elastic.co/t/how-can-we-update-multiple-documents-using-callwithrequest/187578/7 "2019-07-19T17:21:42Z")

</div>

Hello Team,

I was able to achieve it using bulk API with callwithrequest.

Thank you,  
Aditya

---

<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 16, 2019, 5:21pm UTC](https://discuss.elastic.co/t/how-can-we-update-multiple-documents-using-callwithrequest/187578/8 "2019-08-16T17:21:58Z")

</div>

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