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


Java SearchRequest.preference方法代码示例

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


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

示例1: toSearchRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
public SearchRequest toSearchRequest() {
    SearchRequest searchRequest = new SearchRequest(indices());
    searchRequest.indicesOptions(indicesOptions());
    searchRequest.types(types());
    searchRequest.routing(routing());
    searchRequest.preference(preference());
    searchRequest.source(source());
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.size(0);
    if (minScore() != DEFAULT_MIN_SCORE) {
        searchSourceBuilder.minScore(minScore());
    }
    if (terminateAfter() != DEFAULT_TERMINATE_AFTER) {
        searchSourceBuilder.terminateAfter(terminateAfter());
    }
    searchRequest.extraSource(searchSourceBuilder);
    return searchRequest;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:19,代码来源:CountRequest.java

示例2: randomSearchRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
/**
 * Build a random search request.
 *
 * @param randomSearchSourceBuilder builds a random {@link SearchSourceBuilder}. You can use
 *        {@link #randomSearchSourceBuilder(Supplier, Supplier, Supplier, Supplier, Supplier)}.
 */
public static SearchRequest randomSearchRequest(Supplier<SearchSourceBuilder> randomSearchSourceBuilder) throws IOException {
    SearchRequest searchRequest = new SearchRequest();
    if (randomBoolean()) {
        searchRequest.indices(generateRandomStringArray(10, 10, false, false));
    }
    if (randomBoolean()) {
        searchRequest.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
    }
    if (randomBoolean()) {
        searchRequest.types(generateRandomStringArray(10, 10, false, false));
    }
    if (randomBoolean()) {
        searchRequest.preference(randomAsciiOfLengthBetween(3, 10));
    }
    if (randomBoolean()) {
        searchRequest.requestCache(randomBoolean());
    }
    if (randomBoolean()) {
        searchRequest.routing(randomAsciiOfLengthBetween(3, 10));
    }
    if (randomBoolean()) {
        searchRequest.scroll(randomPositiveTimeValue());
    }
    if (randomBoolean()) {
        searchRequest.searchType(randomFrom(SearchType.values()));
    }
    if (randomBoolean()) {
        searchRequest.source(randomSearchSourceBuilder.get());
    }
    return searchRequest;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:RandomSearchRequestGenerator.java

示例3: parseSearchRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
/**
 * Parses the rest request on top of the SearchRequest, preserving values that are not overridden by the rest request.
 *
 * @param requestContentParser body of the request to read. This method does not attempt to read the body from the {@code request}
 *        parameter
 */
public static void parseSearchRequest(SearchRequest searchRequest, RestRequest request,
                                      XContentParser requestContentParser) throws IOException {

    if (searchRequest.source() == null) {
        searchRequest.source(new SearchSourceBuilder());
    }
    searchRequest.indices(Strings.splitStringByCommaToArray(request.param("index")));
    if (requestContentParser != null) {
        QueryParseContext context = new QueryParseContext(requestContentParser);
        searchRequest.source().parseXContent(context);
    }

    final int batchedReduceSize = request.paramAsInt("batched_reduce_size", searchRequest.getBatchedReduceSize());
    searchRequest.setBatchedReduceSize(batchedReduceSize);

    // do not allow 'query_and_fetch' or 'dfs_query_and_fetch' search types
    // from the REST layer. these modes are an internal optimization and should
    // not be specified explicitly by the user.
    String searchType = request.param("search_type");
    if ("query_and_fetch".equals(searchType) ||
            "dfs_query_and_fetch".equals(searchType)) {
        throw new IllegalArgumentException("Unsupported search type [" + searchType + "]");
    } else {
        searchRequest.searchType(searchType);
    }
    parseSearchSource(searchRequest.source(), request);
    searchRequest.requestCache(request.paramAsBoolean("request_cache", null));

    String scroll = request.param("scroll");
    if (scroll != null) {
        searchRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll")));
    }

    searchRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
    searchRequest.routing(request.param("routing"));
    searchRequest.preference(request.param("preference"));
    searchRequest.indicesOptions(IndicesOptions.fromRequest(request, searchRequest.indicesOptions()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:RestSearchAction.java

示例4: copyRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
private static SearchRequest copyRequest(SearchRequest searchRequest) throws IOException {
    SearchRequest result = new SearchRequest();
    result.indices(searchRequest.indices());
    result.indicesOptions(searchRequest.indicesOptions());
    result.types(searchRequest.types());
    result.searchType(searchRequest.searchType());
    result.preference(searchRequest.preference());
    result.routing(searchRequest.routing());
    result.requestCache(searchRequest.requestCache());
    result.scroll(searchRequest.scroll());
    if (searchRequest.source() != null) {
        result.source(searchRequest.source());
    }
    return result;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:SearchRequestTests.java

示例5: prepareRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    SearchRequest countRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index")));
    countRequest.indicesOptions(IndicesOptions.fromRequest(request, countRequest.indicesOptions()));
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0);
    countRequest.source(searchSourceBuilder);
    request.withContentOrSourceParamParserOrNull(parser -> {
        if (parser == null) {
            QueryBuilder queryBuilder = RestActions.urlParamsToQueryBuilder(request);
            if (queryBuilder != null) {
                searchSourceBuilder.query(queryBuilder);
            }
        } else {
            searchSourceBuilder.query(RestActions.getQueryContent(parser));
        }
    });
    countRequest.routing(request.param("routing"));
    float minScore = request.paramAsFloat("min_score", -1f);
    if (minScore != -1f) {
        searchSourceBuilder.minScore(minScore);
    }
    countRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
    countRequest.preference(request.param("preference"));

    final int terminateAfter = request.paramAsInt("terminate_after", DEFAULT_TERMINATE_AFTER);
    if (terminateAfter < 0) {
        throw new IllegalArgumentException("terminateAfter must be > 0");
    } else if (terminateAfter > 0) {
        searchSourceBuilder.terminateAfter(terminateAfter);
    }
    return channel -> client.search(countRequest, new RestBuilderListener<SearchResponse>(channel) {
        @Override
        public RestResponse buildResponse(SearchResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            if (terminateAfter != DEFAULT_TERMINATE_AFTER) {
                builder.field("terminated_early", response.isTerminatedEarly());
            }
            builder.field("count", response.getHits().getTotalHits());
            buildBroadcastShardsHeader(builder, request, response.getTotalShards(), response.getSuccessfulShards(),
                    response.getFailedShards(), response.getShardFailures());

            builder.endObject();
            return new BytesRestResponse(response.status(), builder);
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:47,代码来源:RestCountAction.java

示例6: parseSearchRequest

import org.elasticsearch.action.search.SearchRequest; //导入方法依赖的package包/类
public static void parseSearchRequest(SearchRequest searchRequest, RestRequest request, ParseFieldMatcher parseFieldMatcher,
        BytesReference bodyContent) {
    searchRequest.indices(Strings.splitStringByCommaToArray(request.param("index")));
    // get the content, and put it in the body
    // add content/source as template if template flag is set
    boolean isTemplateRequest = request.path().endsWith("/template");
    if (bodyContent == null) {
        if (RestActions.hasBodyContent(request)) {
            bodyContent = RestActions.getRestContent(request);
        }
    }
    if (bodyContent != null) {
        if (isTemplateRequest) {
            searchRequest.templateSource(bodyContent);
        } else {
            searchRequest.source(bodyContent);
        }
    }

    // do not allow 'query_and_fetch' or 'dfs_query_and_fetch' search types
    // from the REST layer. these modes are an internal optimization and should
    // not be specified explicitly by the user.
    String searchType = request.param("search_type");
    if (SearchType.fromString(searchType, parseFieldMatcher).equals(SearchType.QUERY_AND_FETCH) ||
            SearchType.fromString(searchType, parseFieldMatcher).equals(SearchType.DFS_QUERY_AND_FETCH)) {
        throw new IllegalArgumentException("Unsupported search type [" + searchType + "]");
    } else {
        searchRequest.searchType(searchType);
    }

    searchRequest.extraSource(parseSearchSource(request));
    searchRequest.requestCache(request.paramAsBoolean("request_cache", null));

    String scroll = request.param("scroll");
    if (scroll != null) {
        searchRequest.scroll(new Scroll(parseTimeValue(scroll, null, "scroll")));
    }

    searchRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
    searchRequest.routing(request.param("routing"));
    searchRequest.preference(request.param("preference"));
    searchRequest.indicesOptions(IndicesOptions.fromRequest(request, searchRequest.indicesOptions()));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:44,代码来源:RestSearchAction.java


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