当前位置: 代码迷 >> 综合 >> elasticsearch 笔记七: es乐观锁的并发控制
  详细解决方案

elasticsearch 笔记七: es乐观锁的并发控制

热度:80   发布时间:2023-12-16 17:15:05.0

1.并发控制

es 的并发控制是通过多version来实现的(不清楚乐观锁的自己提升去)

2.实例

//创建索引
PUT /test_index/test_type/7
{"test_field": "test test"
}//返回创建结果GET test_index/test_type/7{"_index": "test_index","_type": "test_type","_id": "7","_version": 1,"found": true,"_source": {"test_field": "test test"}
}******* 根据版本号来更新索引****************
PUT /test_index/test_type/7?version=1 
{"test_field": "test client 1"
}//返回结果
{"_index": "test_index","_type": "test_type","_id": "7","_version": 2,"result": "updated","_shards": {"total": 2,"successful": 1,"failed": 0},"created": false
}******另外一个客户端,尝试基于version=1的数据去进行修改,同样带上version版本号,进行乐观锁的并发控制
  相关解决方案