Vijayakumar
Vijayakumar

Reputation: 338

Bulk update in the elasticsearch

I have a requirement to update a nested document (bulk) in the elasticsearch 5.X

Conditions

  1. I will have multiple document with the same groupid.
  2. I want to update the document's groupname which bares the groupid 244
  3. I have to update them in bulk.

Eg: { "hits": { "hits": [{ "_index": "myindex", "_id": "1", "_source": { "ticketdesc": [{ "groupid": 244, "groupname": "Fire and run" }] } }, { "_index": "myindex", "_id": "2", "_source": { "ticketdesc": [{ "groupid": 244, "groupname": "Fire and run" }] } }, { "_index": "myindex", "_id": "3", "_source": { "ticketdesc": [{ "groupid": 244, "groupname": "Fire and run" }] } }, { "_index": "myindex", "_id": "4", "_source": { "ticketdesc": [{ "groupid": 245, "groupname": "Fire and run" }] } } ] } }

Thanks in advance

Upvotes: 0

Views: 83

Answers (1)

Val
Val

Reputation: 217564

You can do so easily with the update by query API

POST myindex/_update_by_query
{
  "query": {
    "term": {"groupid": 245}
  },
  "script": {
    "source": "ctx._source.groupname = 'New name' "
  }
}

Upvotes: 1

Related Questions