當前位置: 首頁>>代碼示例>>Java>>正文


Java GetRequest.fetchSourceContext方法代碼示例

本文整理匯總了Java中org.elasticsearch.action.get.GetRequest.fetchSourceContext方法的典型用法代碼示例。如果您正苦於以下問題:Java GetRequest.fetchSourceContext方法的具體用法?Java GetRequest.fetchSourceContext怎麽用?Java GetRequest.fetchSourceContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.action.get.GetRequest的用法示例。


在下文中一共展示了GetRequest.fetchSourceContext方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: prepareRequest

import org.elasticsearch.action.get.GetRequest; //導入方法依賴的package包/類
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
    getRequest.operationThreaded(true);
    getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
    getRequest.routing(request.param("routing"));
    getRequest.parent(request.param("parent"));
    getRequest.preference(request.param("preference"));
    getRequest.realtime(request.paramAsBoolean("realtime", getRequest.realtime()));
    if (request.param("fields") != null) {
        throw new IllegalArgumentException("the parameter [fields] is no longer supported, " +
            "please use [stored_fields] to retrieve stored fields or [_source] to load the field from _source");
    }
    final String fieldsParam = request.param("stored_fields");
    if (fieldsParam != null) {
        final String[] fields = Strings.splitStringByCommaToArray(fieldsParam);
        if (fields != null) {
            getRequest.storedFields(fields);
        }
    }

    getRequest.version(RestActions.parseVersion(request));
    getRequest.versionType(VersionType.fromString(request.param("version_type"), getRequest.versionType()));

    getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));

    return channel -> client.get(getRequest, new RestToXContentListener<GetResponse>(channel) {
        @Override
        protected RestStatus getStatus(final GetResponse response) {
            return response.isExists() ? OK : NOT_FOUND;
        }
    });
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:34,代碼來源:RestGetAction.java

示例2: prepareRequest

import org.elasticsearch.action.get.GetRequest; //導入方法依賴的package包/類
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
    getRequest.operationThreaded(true);
    getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
    getRequest.routing(request.param("routing"));
    getRequest.parent(request.param("parent"));
    getRequest.preference(request.param("preference"));
    getRequest.realtime(request.paramAsBoolean("realtime", getRequest.realtime()));

    getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));

    return channel -> {
        if (getRequest.fetchSourceContext() != null && !getRequest.fetchSourceContext().fetchSource()) {
            final ActionRequestValidationException validationError = new ActionRequestValidationException();
            validationError.addValidationError("fetching source can not be disabled");
            channel.sendResponse(new BytesRestResponse(channel, validationError));
        } else {
            client.get(getRequest, new RestResponseListener<GetResponse>(channel) {
                @Override
                public RestResponse buildResponse(final GetResponse response) throws Exception {
                    final XContentBuilder builder = channel.newBuilder(request.getXContentType(), false);
                    // check if doc source (or doc itself) is missing
                    if (response.isSourceEmpty()) {
                        return new BytesRestResponse(NOT_FOUND, builder);
                    } else {
                        builder.rawValue(response.getSourceInternal());
                        return new BytesRestResponse(OK, builder);
                    }
                }
            });
        }
    };
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:35,代碼來源:RestGetSourceAction.java

示例3: handleRequest

import org.elasticsearch.action.get.GetRequest; //導入方法依賴的package包/類
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
    getRequest.operationThreaded(true);
    getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
    getRequest.routing(request.param("routing"));  // order is important, set it after routing, so it will set the routing
    getRequest.parent(request.param("parent"));
    getRequest.preference(request.param("preference"));
    getRequest.realtime(request.paramAsBoolean("realtime", null));
    getRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));

    String sField = request.param("fields");
    if (sField != null) {
        String[] sFields = Strings.splitStringByCommaToArray(sField);
        if (sFields != null) {
            getRequest.fields(sFields);
        }
    }

    getRequest.version(RestActions.parseVersion(request));
    getRequest.versionType(VersionType.fromString(request.param("version_type"), getRequest.versionType()));

    getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));

    client.get(getRequest, new RestBuilderListener<GetResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            response.toXContent(builder, request);
            builder.endObject();
            if (!response.isExists()) {
                return new BytesRestResponse(NOT_FOUND, builder);
            } else {
                return new BytesRestResponse(OK, builder);
            }
        }
    });
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:39,代碼來源:RestGetAction.java

示例4: handleRequest

import org.elasticsearch.action.get.GetRequest; //導入方法依賴的package包/類
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
    getRequest.operationThreaded(true);
    getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
    getRequest.routing(request.param("routing"));  // order is important, set it after routing, so it will set the routing
    getRequest.parent(request.param("parent"));
    getRequest.preference(request.param("preference"));
    getRequest.realtime(request.paramAsBoolean("realtime", null));

    getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));

    if (getRequest.fetchSourceContext() != null && !getRequest.fetchSourceContext().fetchSource()) {
        try {
            ActionRequestValidationException validationError = new ActionRequestValidationException();
            validationError.addValidationError("fetching source can not be disabled");
            channel.sendResponse(new BytesRestResponse(channel, validationError));
        } catch (IOException e) {
            logger.error("Failed to send failure response", e);
        }
    }

    client.get(getRequest, new RestResponseListener<GetResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetResponse response) throws Exception {
            XContentBuilder builder = channel.newBuilder(response.getSourceInternal(), false);
            if (!response.isExists()) {
                return new BytesRestResponse(NOT_FOUND, builder);
            } else {
                builder.rawValue(response.getSourceInternal());
                return new BytesRestResponse(OK, builder);
            }
        }
    });
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:36,代碼來源:RestGetSourceAction.java

示例5: execute

import org.elasticsearch.action.get.GetRequest; //導入方法依賴的package包/類
public void execute(final GetRequest request, final ActionListener<GetResponse> listener) {
    logger.debug("get request {}", request);
    try {
        // encode to handle the case where the id got a space/special char
        RequestUriBuilder uriBuilder = new RequestUriBuilder(request.index(), request.type(), URLEncoder.encode(request.id(), Charsets.UTF_8.displayName()));
        uriBuilder.addIndicesOptions(request);

        FetchSourceContext fetchSourceContext = request.fetchSourceContext();
        if (fetchSourceContext != null) {
            uriBuilder.addQueryParameter("_source", fetchSourceContext.fetchSource());
            if (fetchSourceContext.transformSource()) {
                uriBuilder.addQueryParameter("_source_transform", true);
            }
            // excludes & includes defaults to empty String array
            if (fetchSourceContext.excludes().length > 0) {
                uriBuilder.addQueryParameterArrayAsCommaDelimited("_source_exclude", fetchSourceContext.excludes());
            }
            if (fetchSourceContext.includes().length > 0) {
                uriBuilder.addQueryParameterArrayAsCommaDelimited("_source_include", fetchSourceContext.includes());
            }
        }

        if (request.version() != Versions.MATCH_ANY) {
            uriBuilder.addQueryParameter("version", request.version());
            uriBuilder.addQueryParameter("version_type", request.versionType().toString().toLowerCase());
        }
        if (request.fields() != null) {
            uriBuilder.addQueryParameterArrayAsCommaDelimited("fields", request.fields());
        }
        uriBuilder.addQueryParameterIfNotNull("routing", request.routing());
        uriBuilder.addQueryParameterIfNotNull("preference", request.preference());
        if (request.refresh()) {
            uriBuilder.addQueryParameter("refresh", request.refresh());
        }
        if (request.realtime()) {
            uriBuilder.addQueryParameter("realtime", request.realtime());
        }
        httpClient.getHttpClient().submit(HttpClientRequest.createGet(uriBuilder.toString()))
                .flatMap(ErrorHandler.AS_FUNC)
                .flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<GetResponse>>() {
                    @Override
                    public Observable<GetResponse> call(HttpClientResponse<ByteBuf> response) {
                        return response.getContent().flatMap(new Func1<ByteBuf, Observable<GetResponse>>() {
                            @Override
                            public Observable<GetResponse> call(ByteBuf byteBuf) {
                                return GetResponse.parse(byteBuf);
                            }
                        });
                    }
                })
                .single()
                .subscribe(new ListenerCompleterObserver<>(listener));

    } catch (Exception e) {
        listener.onFailure(e);
    }
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:58,代碼來源:GetActionHandler.java


注:本文中的org.elasticsearch.action.get.GetRequest.fetchSourceContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。