本文整理汇总了Java中org.elasticsearch.action.update.UpdateRequest.routing方法的典型用法代码示例。如果您正苦于以下问题:Java UpdateRequest.routing方法的具体用法?Java UpdateRequest.routing怎么用?Java UpdateRequest.routing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.update.UpdateRequest
的用法示例。
在下文中一共展示了UpdateRequest.routing方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildUpdateCommand
import org.elasticsearch.action.update.UpdateRequest; //导入方法依赖的package包/类
private static byte[] buildUpdateCommand(UpdateRequest updateRequest) throws IOException {
try (XContentBuilder builder = XContentFactory.jsonBuilder().startObject()) {
addCommonOptions(builder, "update", updateRequest.index(), updateRequest.type(), updateRequest.id(),
updateRequest.version(), updateRequest.versionType(), updateRequest.routing(),
updateRequest.consistencyLevel(), updateRequest.refresh());
String timestamp = updateRequest.doc() != null ? updateRequest.doc().timestamp() : null;
long ttl = updateRequest.doc() != null ? updateRequest.doc().ttl() : -1;
if (timestamp != null) {
builder.field("_timestamp", timestamp);
}
if (ttl != -1) {
builder.field("_ttl", ttl);
}
if (updateRequest.retryOnConflict() != -1) {
builder.field("_retry_on_conflict", updateRequest.retryOnConflict());
}
if (updateRequest.fields() != null && updateRequest.fields().length > 0) {
builder.field("_fields", Strings.arrayToCommaDelimitedString(updateRequest.fields()));
}
if (updateRequest.doc() != null && updateRequest.doc().parent() != null) {
builder.field("_parent", updateRequest.doc().parent());
} else if (updateRequest.routing() != null) {
builder.field("_parent", updateRequest.routing());
}
return builder.bytes().toBytes();
}
}
示例2: prepareRequest
import org.elasticsearch.action.update.UpdateRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
UpdateRequest updateRequest = new UpdateRequest(request.param("index"), request.param("type"), request.param("id"));
updateRequest.routing(request.param("routing"));
updateRequest.parent(request.param("parent"));
updateRequest.timeout(request.paramAsTime("timeout", updateRequest.timeout()));
updateRequest.setRefreshPolicy(request.param("refresh"));
String waitForActiveShards = request.param("wait_for_active_shards");
if (waitForActiveShards != null) {
updateRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
}
updateRequest.docAsUpsert(request.paramAsBoolean("doc_as_upsert", updateRequest.docAsUpsert()));
FetchSourceContext fetchSourceContext = FetchSourceContext.parseFromRestRequest(request);
String sField = request.param("fields");
if (sField != null && fetchSourceContext != null) {
throw new IllegalArgumentException("[fields] and [_source] cannot be used in the same request");
}
if (sField != null) {
DEPRECATION_LOGGER.deprecated("Deprecated field [fields] used, expected [_source] instead");
String[] sFields = Strings.splitStringByCommaToArray(sField);
updateRequest.fields(sFields);
} else if (fetchSourceContext != null) {
updateRequest.fetchSource(fetchSourceContext);
}
updateRequest.retryOnConflict(request.paramAsInt("retry_on_conflict", updateRequest.retryOnConflict()));
updateRequest.version(RestActions.parseVersion(request));
updateRequest.versionType(VersionType.fromString(request.param("version_type"), updateRequest.versionType()));
request.applyContentParser(parser -> {
updateRequest.fromXContent(parser);
IndexRequest upsertRequest = updateRequest.upsertRequest();
if (upsertRequest != null) {
upsertRequest.routing(request.param("routing"));
upsertRequest.parent(request.param("parent"));
upsertRequest.version(RestActions.parseVersion(request));
upsertRequest.versionType(VersionType.fromString(request.param("version_type"), upsertRequest.versionType()));
}
IndexRequest doc = updateRequest.doc();
if (doc != null) {
doc.routing(request.param("routing"));
doc.parent(request.param("parent")); // order is important, set it after routing, so it will set the routing
doc.version(RestActions.parseVersion(request));
doc.versionType(VersionType.fromString(request.param("version_type"), doc.versionType()));
}
});
return channel ->
client.update(updateRequest, new RestStatusToXContentListener<>(channel, r -> r.getLocation(updateRequest.routing())));
}