简体   繁体   中英

Update Elasticsearch document which has multiple array

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

Conditions

  1. I have to update a groupname based on the groupid.
  2. A block will have multiple group id block.
  3. I need to update group name for only groupid 245.If i update one block another block should not get affected. It should remain as it is.
  4. I have to update them in bulk.

     { "hits": [{ "_index": "myindex", "_id": "1", "_source": { "TicketSet": [{ "Tasks": [{ "Group": { "Id": 245, "Name": "Name 245" } }, { "Group": { "Id": 244, "Name": "Name 244" } }] }] } }, { "_index": "myindex", "_id": "3", "_source": { "TicketSet": [{ "Tasks": [{ "Group": { "Id": 245, "Name": "Name 245" } }, { "Group": { "Id": 244, "Name": "Name 244" } }] }] } }] 

    }

You can do so easily with the update by query API (I made the assumption that ticketdesc is nested ):

POST tickets/_update_by_query
{
  "query": {
     "term": {
       "TicketSet.Tasks.Group.Id": 245
     }
  },
  "script": {
    "inline": "ctx._source.TicketSet[0].Tasks.stream().filter(g -> g.Group.Id == params.groupId).forEach(g -> g.Group.Name = params.newName)",
    "params": {
      "groupId": 245,
      "newName": "New name"
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM