How can we update multiple documents using callwithrequest

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

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

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

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"
        }
      }
    }

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

I hope this help. :slight_smile:

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

Hello Team,

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

Thank you,
Aditya

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