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


Java Client.get方法代码示例

本文整理汇总了Java中org.elasticsearch.client.Client.get方法的典型用法代码示例。如果您正苦于以下问题:Java Client.get方法的具体用法?Java Client.get怎么用?Java Client.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.client.Client的用法示例。


在下文中一共展示了Client.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleRequest

import org.elasticsearch.client.Client; //导入方法依赖的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));
    // don't get any fields back...
    getRequest.fields(Strings.EMPTY_ARRAY);
    // TODO we can also just return the document size as Content-Length

    client.get(getRequest, new RestResponseListener<GetResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetResponse response) {
            if (!response.isExists()) {
                return new BytesRestResponse(NOT_FOUND);
            } else {
                return new BytesRestResponse(OK);
            }
        }
    });
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:25,代码来源:RestHeadAction.java

示例2: handleRequest

import org.elasticsearch.client.Client; //导入方法依赖的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

示例3: handleRequest

import org.elasticsearch.client.Client; //导入方法依赖的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


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