嗨,我有一个文档是这样构建的:
{
id:1231,
search_and_match_data:{....some nested data},
backoffice_data:{ ....some nested data },
number_of_tries:0
}
我确实进行了部分更新,仅更新了一个backofficeField,但是我希望每次更新number_of_tries时都能够递增。 有可能做吗? 我已经找到了使用脚本进行递增的方法,但是我得到了
org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: can't provide both script and doc;
这是我的代码
private final Object lock = new Object();
private final RestHighLevelClient restHighLevelClient;
void updateBackOfficeField(final String listingId, final BackOfficeData data) throws IOException {
final UpdateRequest updateRequest = getUpdateRequest(listingId, toJson(data));
update(updateRequest);
}
private UpdateRequest getUpdateRequest(final String listingId, final XContentBuilder json) {
final UpdateRequest updateRequest = new UpdateRequest();
updateRequest.index(ELASTICSEARCH_LISTINGS_INDEX);
updateRequest.type(ELASTICSEARCH_TYPE);
updateRequest.id(listingId);
updateRequest.doc(json);
return updateRequest;
}
private UpdateResponse update(final UpdateRequest updateRequest) throws IOException {
synchronized (lock) {
return restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
}
}
有什么方法可以让Elasticsearch在更新期间自动增加字段吗?