/** * Sets the versioning type. Defaults to {@link org.elasticsearch.index.VersionType#INTERNAL}. */ public UpdateRequestBuilder setVersionType(VersionType versionType) { request.versionType(versionType); return this; }
/** * Calculate the version to use for the update request, using either the existing version if internal versioning is used, or the get * result document's version if the version type is "FORCE". */ static long calculateUpdateVersion(UpdateRequest request, GetResult getResult) { if (request.versionType() != VersionType.INTERNAL) { assert request.versionType() == VersionType.FORCE; return request.version(); // remember, match_any is excluded by the conflict test } else { return getResult.getVersion(); } }
parameters.withRetryOnConflict(updateRequest.retryOnConflict()); parameters.withVersion(updateRequest.version()); parameters.withVersionType(updateRequest.versionType());
/** * Prepares an update request by converting it into an index or delete request or an update response (no action). */ public Result prepare(UpdateRequest request, IndexShard indexShard, LongSupplier nowInMillis) { final GetResult getResult = indexShard.getService().getForUpdate(request.type(), request.id(), request.version(), request.versionType()); return prepare(indexShard.shardId(), request, getResult, nowInMillis); }
/** * Sets the versioning type. Defaults to {@link org.elasticsearch.index.VersionType#INTERNAL}. */ public UpdateRequestBuilder setVersionType(VersionType versionType) { request.versionType(versionType); return this; }
/** * Sets the versioning type. Defaults to {@link org.elasticsearch.index.VersionType#INTERNAL}. */ public UpdateRequestBuilder setVersionType(VersionType versionType) { request.versionType(versionType); return this; }
/** * Sets the versioning type. Defaults to {@link org.elasticsearch.index.VersionType#INTERNAL}. */ public UpdateRequestBuilder setVersionType(VersionType versionType) { request.versionType(versionType); return this; }
/** * Sets the versioning type. Defaults to {@link org.elasticsearch.index.VersionType#INTERNAL}. */ public UpdateRequestBuilder setVersionType(VersionType versionType) { request.versionType(versionType); return this; }
final IndexRequest indexRequest = Requests.indexRequest(request.index()) .type(request.type()).id(request.id()).routing(routing).parent(parent) .source(updatedSourceAsMap, updateSourceContentType).version(updateVersion).versionType(request.versionType()) .waitForActiveShards(request.waitForActiveShards()).timeout(request.timeout()) .setRefreshPolicy(request.getRefreshPolicy()); DeleteRequest deleteRequest = Requests.deleteRequest(request.index()) .type(request.type()).id(request.id()).routing(routing).parent(parent) .version(updateVersion).versionType(request.versionType()).waitForActiveShards(request.waitForActiveShards()) .timeout(request.timeout()).setRefreshPolicy(request.getRefreshPolicy()); return new Result(deleteRequest, DocWriteResponse.Result.DELETED, updatedSourceAsMap, updateSourceContentType);
/** * Calculate the version to use for the update request, using either the existing version if internal versioning is used, or the get * result document's version if the version type is "FORCE". */ static long calculateUpdateVersion(UpdateRequest request, GetResult getResult) { if (request.versionType() != VersionType.INTERNAL) { assert request.versionType() == VersionType.FORCE; return request.version(); // remember, match_any is excluded by the conflict test } else { return getResult.getVersion(); } }
/** * Calculate the version to use for the update request, using either the existing version if internal versioning is used, or the get * result document's version if the version type is "FORCE". */ static long calculateUpdateVersion(UpdateRequest request, GetResult getResult) { if (request.versionType() != VersionType.INTERNAL) { assert request.versionType() == VersionType.FORCE; return request.version(); // remember, match_any is excluded by the conflict test } else { return getResult.getVersion(); } }
if (request.versionType() != VersionType.INTERNAL) { indexRequest.version(request.version()).versionType(request.versionType());
} else if ("update".equals(action)) { UpdateRequest updateRequest = new UpdateRequest(index, type, id).routing(routing).parent(parent) .retryOnConflict(retryOnConflict).version(version).versionType(versionType) .routing(routing) .parent(parent);
updateRequest.versionType(VersionType.fromString(request.param("version_type"), updateRequest.versionType()));
/** * Prepare the request for merging the existing document with a new one, can optionally detect a noop change. Returns a {@code Result} * containing a new {@code IndexRequest} to be executed on the primary and replicas. */ Result prepareUpdateIndexRequest(ShardId shardId, UpdateRequest request, GetResult getResult, boolean detectNoop) { final long updateVersion = calculateUpdateVersion(request, getResult); final IndexRequest currentRequest = request.doc(); final String routing = calculateRouting(getResult, currentRequest); final String parent = calculateParent(getResult, currentRequest); final Tuple<XContentType, Map<String, Object>> sourceAndContent = XContentHelper.convertToMap(getResult.internalSourceRef(), true); final XContentType updateSourceContentType = sourceAndContent.v1(); final Map<String, Object> updatedSourceAsMap = sourceAndContent.v2(); final boolean noop = !XContentHelper.update(updatedSourceAsMap, currentRequest.sourceAsMap(), detectNoop); // We can only actually turn the update into a noop if detectNoop is true to preserve backwards compatibility and to handle cases // where users repopulating multi-fields or adding synonyms, etc. if (detectNoop && noop) { UpdateResponse update = new UpdateResponse(shardId, getResult.getType(), getResult.getId(), getResult.getVersion(), DocWriteResponse.Result.NOOP); update.setGetResult(extractGetResult(request, request.index(), getResult.getSeqNo(), getResult.getPrimaryTerm(), getResult.getVersion(), updatedSourceAsMap, updateSourceContentType, getResult.internalSourceRef())); return new Result(update, DocWriteResponse.Result.NOOP, updatedSourceAsMap, updateSourceContentType); } else { final IndexRequest finalIndexRequest = Requests.indexRequest(request.index()) .type(request.type()).id(request.id()).routing(routing).parent(parent) .source(updatedSourceAsMap, updateSourceContentType).version(updateVersion).versionType(request.versionType()) .waitForActiveShards(request.waitForActiveShards()).timeout(request.timeout()) .setRefreshPolicy(request.getRefreshPolicy()); return new Result(finalIndexRequest, DocWriteResponse.Result.UPDATED, updatedSourceAsMap, updateSourceContentType); } }
/** * Prepares an update request by converting it into an index or delete request or an update response (no action). */ @SuppressWarnings("unchecked") public Result prepare(UpdateRequest request, IndexShard indexShard) { final GetResult getResult = indexShard.getService().get(request.type(), request.id(), new String[]{RoutingFieldMapper.NAME, ParentFieldMapper.NAME, TTLFieldMapper.NAME, TimestampFieldMapper.NAME}, true, request.version(), request.versionType(), FetchSourceContext.FETCH_SOURCE, false); return prepare(request, getResult); }
/** * Prepares an update request by converting it into an index or delete request or an update response (no action). */ public Result prepare(UpdateRequest request, IndexShard indexShard, LongSupplier nowInMillis) { final GetResult getResult = indexShard.getService().getForUpdate(request.type(), request.id(), request.version(), request.versionType()); return prepare(indexShard.shardId(), request, getResult, nowInMillis); }
/** * Prepares an update request by converting it into an index or delete request or an update response (no action). */ public Result prepare(UpdateRequest request, IndexShard indexShard, LongSupplier nowInMillis) { final GetResult getResult = indexShard.getService().get(request.type(), request.id(), new String[]{RoutingFieldMapper.NAME, ParentFieldMapper.NAME, TTLFieldMapper.NAME, TimestampFieldMapper.NAME}, true, request.version(), request.versionType(), FetchSourceContext.FETCH_SOURCE); return prepare(indexShard.shardId(), request, getResult, nowInMillis); }
/** * Prepares an update request by converting it into an index or delete request or an update response (no action). */ public Result prepare(UpdateRequest request, IndexShard indexShard, LongSupplier nowInMillis) { final GetResult getResult = indexShard.getService().getForUpdate(request.type(), request.id(), request.version(), request.versionType()); return prepare(indexShard.shardId(), request, getResult, nowInMillis); }
private void applyVersion(BulkItemRequest item, long version, VersionType versionType) { if (item.request() instanceof IndexRequest) { ((IndexRequest) item.request()).version(version).versionType(versionType); } else if (item.request() instanceof DeleteRequest) { ((DeleteRequest) item.request()).version(version).versionType(); } else if (item.request() instanceof UpdateRequest) { ((UpdateRequest) item.request()).version(version).versionType(); } else { // log? } }