ES的JAVA客户端7.6版本现在支持version乐观锁吗?我查了很多资料,java客户端现在如果不支持version的乐观锁,现在最新版本如何使用乐观锁?
我使用了如下代码进行version版本控制:
```java
IndexRequest indexRequest =
new IndexRequest(indexName)
.id(id)
.source(json, XContentType.JSON)
.opType(opType).version(version == null ? Versions.MATCH_ANY : version);
return client().index(indexRequest, RequestOptions.DEFAULT);
```
使用 postman 测试给出以下响应:
```java
{
"error": {
"root_cause": [
{
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: internal versioning can not be used for optimistic concurrency control. Please use `if_seq_no` and `if_primary_term` instead;"
}
],
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: internal versioning can not be used for optimistic concurrency control. Please use `if_seq_no` and `if_primary_term` instead;"
},
"status": 400
}
```
我使用了如下代码进行version版本控制:
```java
IndexRequest indexRequest =
new IndexRequest(indexName)
.id(id)
.source(json, XContentType.JSON)
.opType(opType).version(version == null ? Versions.MATCH_ANY : version);
return client().index(indexRequest, RequestOptions.DEFAULT);
```
使用 postman 测试给出以下响应:
```java
{
"error": {
"root_cause": [
{
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: internal versioning can not be used for optimistic concurrency control. Please use `if_seq_no` and `if_primary_term` instead;"
}
],
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: internal versioning can not be used for optimistic concurrency control. Please use `if_seq_no` and `if_primary_term` instead;"
},
"status": 400
}
```
0 个回复