我需要在Elasticsearch 5.X中更新文档(批量)
条件
我必须批量更新它们。
{
"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"
}
}]
}]
}
}]
}
答案 0 :(得分:0)
您可以使用update by query API轻松地做到这一点(我假设ticketdesc
是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"
}
}
}