当前位置: 首页>>代码示例>>Java>>正文


Java UpdateRequest.routing方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:30,代码来源:BulkActionMarshaller.java

示例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())));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:52,代码来源:RestUpdateAction.java


注:本文中的org.elasticsearch.action.update.UpdateRequest.routing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。