Validation Failed: 1: compare and write operations can not be used with upsert;
i可以将此错误追溯到此
validate
方法,但是我找不到有关为什么不能这样做的解释,也无法在不遇到冲突的情况下进行UPSERT。在这里我在代码中获得错误的地方:
private UpdateResponse doAction(UUID esId, List<Comment> comments, dSeqNoPrimaryTerm seqPrimNo, String indexName) {
UpdateResponse response = null;
Map<String, Object> params = new HashMap<>();
params.put("comments", comments);
Builder builder = UpdateQuery
.builder(esId.toString())
.withDocAsUpsert(true)
.withDocument(Document.from(params))
.withRefresh(Refresh.True);
if (seqPrimNo != null) {
builder.withIfSeqNo((int) seqPrimNo.getSequenceNumber());
builder.withIfPrimaryTerm((int) seqPrimNo.getPrimaryTerm());
}
UpdateQuery query = builder.build();
response = elasticsearchTemplate.update(query, IndexCoordinates.of(indexName)); // <-- ERRORS HERE
return response;
}
这意味着我们在进行UPSERT时无法进行乐观的锁定? 我想念什么?
i最终使用了最新版本的春季,并进行了以下操作:
Builder b = UpdateQuery.builder(id)
.withDocument(Map.of("field 1","value 1"))
.withRefreshPolicy(...)
...
// check seq no and some other stuff
UpdateQuery uq = b.build();
// run client and get response