Elasticsearch partial update
partial update 似乎已经不再是 Elasticsearch 的主流,但还是记录一下。文字内容整理自 B 站中华石杉的 Elasticsearch 顶尖高手系列课程核心知识篇
partial update,看起来很方便的操作,实际内部的原理是什么样子的,然后它的优点是什么?
其实,Elasticsearch 内部对 partial update 的实际执行跟传统的全量替换方式,是几乎一样的。
partial update 相较于全量替换的优点
# 7.7
PUT test_index/_doc/11
{
"test_field1": "test1",
"test_field2": "test2"
}
# 5.2
PUT /test_index/test_type/10
{
"test_field1": "test1",
"test_field2": "test2"
}
# 7.7
POST test_index/_update/11
{
"doc": {
"test_field2": "partial updated test2"
}
}
# 5.2
POST /test_index/test_type/10/_update
{
"doc": {
"test_field2": "updated test2"
}
}
partial update 同样会自动执行之前讲过的乐观锁的并发控制。
post /index/type/id/_update?retry_on_conflict=5&version=6
retry 策略
后来看了一下,似乎 partial update 的说法已经不再是主流,简单记录一下。

partial update 的步骤:
Document-Based Replication
When a primary shard forwards changes to its replica shards, it doesn’t forward the update request. Instead it forwards the new version of the full document. Remember that these changes are forwarded to the replica shards asynchronously, and there is no guarantee that they will arrive in the same order that they were sent. If Elasticsearch forwarded just the change, it is possible that changes would be applied in the wrong order, resulting in a corrupt document.