http://localhost:9200/user/_update_by_query?冲突=继续
{
"script": {
"source": "ctx._source.age = params.age",
"lang": "painless",
"params": {
"age": 10
}
},
"size": 1000,
"query": {
"term": {
"age": {
"value": 20,
"boost": 1.0
}
}
}
}
字符串
回复:
{
"took": 28,
"timed_out": false,
"total": 1,
"updated": 1,
"deleted": 0,
"batches": 1,
"version_conflicts": 0,
"noops": 0,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"requests_per_second": -1.0,
"throttled_until_millis": 0,
"failures": []
}
型
- total:成功处理的文档数。
- updated:成功更新的文档数。
我不知道什么是真正的意义上的全部财产。如果是查询的计数,我可以检查total是否等于updated**。
//解决方案一
if (response.getTotal() == response.getUpdated()) {
//all updated
} else {
//some documents failed, retry latter
}
型
//解决方案二
if (response.getVersionConflicts() == 0 && CollectionUtils.isEmpty(response.getFailures())) {
//all updated
} else {
//some documents failed, retry latter
}
型
1条答案
按热度按时间eqzww0vc1#
编辑:
如果您没有在
_update_by_query
请求头中指定wait_for_completion=false
,则可以通过以下API调用找到task_id
:字符串
当你运行
_update_by_query
API时,Elasticsearch将创建一个task_id
。如果保存task_id,则可以使用以下命令检查状态:型
如果您没有保存
task_id
,您可以使用_tasks
API进行检查,并找到您的task_id,如果通过查询更新仍然运行。型
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html#docs-update-by-query-fetch-tasks
使用
wait_for_completion=false
获取task_id作为输出。举例如下:
型
completed
显示_update_by_query
是否完成。tasks.status.total
显示总文档数。tasks.status.updated
显示更新的文档数。注意:如果启用了
slice
,则在此过程完成之前无法看到count
。获取带切片的请求的任务的状态仅包含已完成切片的状态。