當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。