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


Java GetRequest.version方法代码示例

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


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

示例1: parseExistingDocPercolate

import org.elasticsearch.action.get.GetRequest; //导入方法依赖的package包/类
void parseExistingDocPercolate(PercolateRequest percolateRequest, RestRequest restRequest, RestChannel restChannel, final Client client) {
    String index = restRequest.param("index");
    String type = restRequest.param("type");
    percolateRequest.indices(Strings.splitStringByCommaToArray(restRequest.param("percolate_index", index)));
    percolateRequest.documentType(restRequest.param("percolate_type", type));

    GetRequest getRequest = new GetRequest(index, type,
            restRequest.param("id"));
    getRequest.routing(restRequest.param("routing"));
    getRequest.preference(restRequest.param("preference"));
    getRequest.refresh(restRequest.paramAsBoolean("refresh", getRequest.refresh()));
    getRequest.realtime(restRequest.paramAsBoolean("realtime", null));
    getRequest.version(RestActions.parseVersion(restRequest));
    getRequest.versionType(VersionType.fromString(restRequest.param("version_type"), getRequest.versionType()));

    percolateRequest.getRequest(getRequest);
    percolateRequest.routing(restRequest.param("percolate_routing"));
    percolateRequest.preference(restRequest.param("percolate_preference"));
    percolateRequest.source(RestActions.getRestContent(restRequest));

    percolateRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, percolateRequest.indicesOptions()));
    executePercolate(percolateRequest, restChannel, client);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:RestPercolateAction.java

示例2: doRewrite

import org.elasticsearch.action.get.GetRequest; //导入方法依赖的package包/类
@Override
protected QueryBuilder doRewrite(QueryRewriteContext queryShardContext) throws IOException {
    if (document != null) {
        return this;
    }

    GetRequest getRequest = new GetRequest(indexedDocumentIndex, indexedDocumentType, indexedDocumentId);
    getRequest.preference("_local");
    getRequest.routing(indexedDocumentRouting);
    getRequest.preference(indexedDocumentPreference);
    if (indexedDocumentVersion != null) {
        getRequest.version(indexedDocumentVersion);
    }
    GetResponse getResponse = queryShardContext.getClient().get(getRequest).actionGet();
    if (getResponse.isExists() == false) {
        throw new ResourceNotFoundException(
                "indexed document [{}/{}/{}] couldn't be found", indexedDocumentIndex, indexedDocumentType, indexedDocumentId
        );
    }
    if(getResponse.isSourceEmpty()) {
        throw new IllegalArgumentException(
            "indexed document [" + indexedDocumentIndex + "/" + indexedDocumentType + "/" + indexedDocumentId + "] source disabled"
        );
    }
    final BytesReference source = getResponse.getSourceAsBytesRef();
    return new PercolateQueryBuilder(field, documentType, source, XContentFactory.xContentType(source));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:PercolateQueryBuilder.java

示例3: 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

示例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.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

示例5: getAndExistsTest

import org.elasticsearch.action.get.GetRequest; //导入方法依赖的package包/类
private static void getAndExistsTest(Function<GetRequest, Request> requestConverter, String method) {
    String index = randomAsciiOfLengthBetween(3, 10);
    String type = randomAsciiOfLengthBetween(3, 10);
    String id = randomAsciiOfLengthBetween(3, 10);
    GetRequest getRequest = new GetRequest(index, type, id);

    Map<String, String> expectedParams = new HashMap<>();
    if (randomBoolean()) {
        if (randomBoolean()) {
            String preference = randomAsciiOfLengthBetween(3, 10);
            getRequest.preference(preference);
            expectedParams.put("preference", preference);
        }
        if (randomBoolean()) {
            String routing = randomAsciiOfLengthBetween(3, 10);
            getRequest.routing(routing);
            expectedParams.put("routing", routing);
        }
        if (randomBoolean()) {
            boolean realtime = randomBoolean();
            getRequest.realtime(realtime);
            if (realtime == false) {
                expectedParams.put("realtime", "false");
            }
        }
        if (randomBoolean()) {
            boolean refresh = randomBoolean();
            getRequest.refresh(refresh);
            if (refresh) {
                expectedParams.put("refresh", "true");
            }
        }
        if (randomBoolean()) {
            long version = randomLong();
            getRequest.version(version);
            if (version != Versions.MATCH_ANY) {
                expectedParams.put("version", Long.toString(version));
            }
        }
        if (randomBoolean()) {
            VersionType versionType = randomFrom(VersionType.values());
            getRequest.versionType(versionType);
            if (versionType != VersionType.INTERNAL) {
                expectedParams.put("version_type", versionType.name().toLowerCase(Locale.ROOT));
            }
        }
        if (randomBoolean()) {
            int numStoredFields = randomIntBetween(1, 10);
            String[] storedFields = new String[numStoredFields];
            StringBuilder storedFieldsParam = new StringBuilder();
            for (int i = 0; i < numStoredFields; i++) {
                String storedField = randomAsciiOfLengthBetween(3, 10);
                storedFields[i] = storedField;
                storedFieldsParam.append(storedField);
                if (i < numStoredFields - 1) {
                    storedFieldsParam.append(",");
                }
            }
            getRequest.storedFields(storedFields);
            expectedParams.put("stored_fields", storedFieldsParam.toString());
        }
        if (randomBoolean()) {
            randomizeFetchSourceContextParams(getRequest::fetchSourceContext, expectedParams);
        }
    }
    Request request = requestConverter.apply(getRequest);
    assertEquals("/" + index + "/" + type + "/" + id, request.endpoint);
    assertEquals(expectedParams, request.params);
    assertNull(request.entity);
    assertEquals(method, request.method);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:72,代码来源:RequestTests.java

示例6: execute

import org.elasticsearch.action.get.GetRequest; //导入方法依赖的package包/类
public void execute(PercolateRequest request, final ActionListener<PercolateResponse> listener) {
    logger.debug("percolate request {}", request);
    // percolate_format does not exist in PercolateRequest, only in REST API
    RequestUriBuilder uriBuilder;

    GetRequest getRequest = request.getRequest();
    try {
        if (getRequest != null) {
            if (getRequest.id() != null) {
                uriBuilder = new RequestUriBuilder(getRequest.index(), getRequest.type(), getRequest.id());
            } else {
                uriBuilder = new RequestUriBuilder(getRequest.index(), getRequest.type());
            }
        } else {
            uriBuilder = new RequestUriBuilder(HttpRequestUtils.indicesOrAll(request), request.documentType());
        }

        if (request.onlyCount()) {
            uriBuilder.addEndpoint("/_percolate/count");
        } else {
            uriBuilder.addEndpoint("/_percolate");
        }

        if (getRequest != null) {
            uriBuilder.addQueryParameterIfNotNull("routing", getRequest.routing());
            uriBuilder.addQueryParameterIfNotNull("preference", getRequest.preference());
            if (getRequest.version() != Versions.MATCH_ANY) {
                uriBuilder.addQueryParameter("version", getRequest.version());
            }
            // percolating an existing doc
            uriBuilder.addQueryParameterIfNotNull("percolate_routing", request.routing());
            uriBuilder.addQueryParameterIfNotNull("percolate_preference", request.preference());
            uriBuilder.addQueryParameterArrayAsCommaDelimitedIfNotNullNorEmpty("percolate_index", request.indices());
            uriBuilder.addQueryParameterIfNotNull("percolate_type", request.documentType());

        } else {
            // params does not have the same meaning in percolate_doc and percolate_existing_doc
            uriBuilder.addQueryParameterIfNotNull("routing", request.routing());
            uriBuilder.addQueryParameterIfNotNull("preference", request.preference());
            uriBuilder.addQueryParameterIfNotNull("type", request.documentType());
        }
        uriBuilder.addIndicesOptions(request);

        uriBuilder.addQueryParameter("pretty", true);
        HttpClientRequest<ByteBuf> httpRequest = HttpClientRequest.createGet(uriBuilder.toString());

        if (request.source() != null) {
            httpRequest.withContent(request.source().toBytes());
        }

        httpClient.getHttpClient().submit(httpRequest)
                .flatMap(ErrorHandler.AS_FUNC)
                .flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<PercolateResponse>>() {
                    @Override
                    public Observable<PercolateResponse> call(final HttpClientResponse<ByteBuf> response) {
                        return response.getContent().flatMap(new Func1<ByteBuf, Observable<PercolateResponse>>() {
                            @Override
                            public Observable<PercolateResponse> call(ByteBuf byteBuf) {
                                return PercolateResponse.parse(byteBuf);
                            }
                        });
                    }
                })
                .single()
                .subscribe(new ListenerCompleterObserver<>(listener));

    } catch (Exception e) {
        listener.onFailure(e);
    }
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:71,代码来源:PercolateActionHandler.java

示例7: writeHeader

import org.elasticsearch.action.get.GetRequest; //导入方法依赖的package包/类
private static BytesReference writeHeader(PercolateRequest request) throws IOException {
        try (XContentBuilder builder = XContentFactory.jsonBuilder().startObject()) {
            if(request.onlyCount()) {
                builder.startObject("count");
            } else {
                builder.startObject("percolate");
            }

            GetRequest getRequest = request.getRequest();
            if(getRequest != null) {
                builder.field("index", getRequest.index());
                builder.field("type", getRequest.type());
                builder.field("id", getRequest.id());
                if(getRequest.refresh()) {
                    builder.field("refresh", getRequest.refresh());
                }
                if(getRequest.realtime()) {
                    builder.field("realtime", getRequest.realtime());
                }
                if(getRequest.preference() != null) {
                    builder.field("preference", request.preference());
                }
                if(getRequest.routing() != null) {
                    builder.field("routing", request.routing());
                }
                if(getRequest.version() != MATCH_ANY) {
                    builder.field("version", getRequest.version());
                }
                if(getRequest.versionType() != VersionType.INTERNAL) {
                    builder.field("version_type", getRequest.versionType());
                }

                if(request.preference() != null) {
                    builder.field("percolate_preference", request.preference());
                }
                if(request.routing() != null) {
                    builder.field("percolate_routing", request.routing());
                }

                if(request.indices() != null && request.indices().length != 0) {
                    builder.field("percolate_index", Strings.arrayToCommaDelimitedString(request.indices()));
                }
                if(request.documentType() != null) {
                    builder.field("percolate_type", request.documentType());
                }
            } else {
                if(request.preference() != null) {
                    builder.field("preference", request.preference());
                }
                if(request.routing() != null) {
                    builder.field("routing", request.routing());
                }
                if(request.indices() != null && request.indices().length != 0) {
                    builder.field("index", Strings.arrayToCommaDelimitedString(request.indices()));
                }
                if(request.documentType() != null) {
                    builder.field("type", request.documentType());
                }
            }

            // TODO add a flag to disable ?
            // needs https://github.com/elastic/elasticsearch/pull/10307 to be merged
//            IndicesOptions indicesOptions = request.indicesOptions();
//            if(indicesOptions.expandWildcardsClosed() & indicesOptions.expandWildcardsOpen()) {
//                builder.field("expand_wildcards", "open,closed");
//            } else if(indicesOptions.expandWildcardsClosed()) {
//                builder.field("expand_wildcards", "closed");
//            } else if(indicesOptions.expandWildcardsOpen()) {
//                builder.field("expand_wildcards", "open");
//            }

            builder.endObject();
            builder.endObject();
            return builder.bytes();
        }
    }
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:77,代码来源:PercolateRequestsMarshaller.java

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