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


Java MultiSearchRequest类代码示例

本文整理汇总了Java中org.elasticsearch.action.search.MultiSearchRequest的典型用法代码示例。如果您正苦于以下问题:Java MultiSearchRequest类的具体用法?Java MultiSearchRequest怎么用?Java MultiSearchRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testSimpleMultiSearchMoreRequests

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
public void testSimpleMultiSearchMoreRequests() {
    createIndex("test");
    int numDocs = randomIntBetween(0, 16);
    for (int i = 0; i < numDocs; i++) {
        client().prepareIndex("test", "type", Integer.toString(i)).setSource("{}", XContentType.JSON).get();
    }
    refresh();

    int numSearchRequests = randomIntBetween(1, 64);
    MultiSearchRequest request = new MultiSearchRequest();
    if (randomBoolean()) {
        request.maxConcurrentSearchRequests(randomIntBetween(1, numSearchRequests));
    }
    for (int i = 0; i < numSearchRequests; i++) {
        request.add(client().prepareSearch("test"));
    }

    MultiSearchResponse response = client().multiSearch(request).actionGet();
    assertThat(response.getResponses().length, equalTo(numSearchRequests));
    for (MultiSearchResponse.Item item : response) {
        assertNoFailures(item.getResponse());
        assertHitCount(item.getResponse(), numDocs);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:MultiSearchIT.java

示例2: parseRequest

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
/**
 * Parses a {@link RestRequest} body and returns a {@link MultiSearchRequest}
 */
public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex) throws IOException {
    MultiSearchRequest multiRequest = new MultiSearchRequest();
    if (restRequest.hasParam("max_concurrent_searches")) {
        multiRequest.maxConcurrentSearchRequests(restRequest.paramAsInt("max_concurrent_searches", 0));
    }

    parseMultiLineRequest(restRequest, multiRequest.indicesOptions(), allowExplicitIndex, (searchRequest, parser) -> {
        try {
            final QueryParseContext queryParseContext = new QueryParseContext(parser);
            searchRequest.source(SearchSourceBuilder.fromXContent(queryParseContext));
            multiRequest.add(searchRequest);
        } catch (IOException e) {
            throw new ElasticsearchParseException("Exception when parsing search request", e);
        }
    });

    return multiRequest;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:RestMultiSearchAction.java

示例3: toMultiSearchRequest

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
protected MultiSearchRequest toMultiSearchRequest(final MultiGetRequest multiGetRequest) {

        final MultiSearchRequest msearch = new MultiSearchRequest();
        msearch.copyContextFrom(multiGetRequest);

        for (final Iterator<Item> iterator = multiGetRequest.iterator(); iterator.hasNext();) {
            final Item item = iterator.next();

            final SearchRequest st = new SearchRequest();
            st.routing(item.routing());
            st.indices(item.indices());
            st.types(item.type());
            st.preference(multiGetRequest.preference());
            st.source(SearchSourceBuilder.searchSource().query(new IdsQueryBuilder(item.type()).addIds(item.id())));
            msearch.add(st);
        }

        return msearch;

    }
 
开发者ID:petalmd,项目名称:armor,代码行数:21,代码来源:AbstractActionFilter.java

示例4: testMultiSearchRequestBuilder

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
@Test
public void testMultiSearchRequestBuilder() throws IOException {
    SuggestionsRestService tested = new SuggestionsRestService();
    tested.searchClientService = Mockito.mock(SearchClientService.class);
    tested.log = Logger.getLogger("testlogger");

    MultiSearchRequestBuilder msrb = new MultiSearchRequestBuilder(null);
    SearchRequestBuilder srbNGram = new SearchRequestBuilder(null);
    SearchRequestBuilder srbFuzzy = new SearchRequestBuilder(null);

    msrb = tested.getProjectMultiSearchRequestBuilder(msrb,
            tested.getProjectSearchNGramRequestBuilder(srbNGram, "JBoss", 5),
            tested.getProjectSearchFuzzyRequestBuilder(srbFuzzy, "JBoss", 5));

    MultiSearchRequest msr = msrb.request();

    Assert.assertEquals(2, msr.requests().size());
}
 
开发者ID:macanhhuy,项目名称:dcp-api,代码行数:19,代码来源:SuggestionsRestServiceTest.java

示例5: handleRequest

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
    MultiSearchRequest multiSearchRequest = new MultiSearchRequest();

    String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    String[] types = Strings.splitStringByCommaToArray(request.param("type"));
    String path = request.path();
    boolean isTemplateRequest = isTemplateRequest(path);
    IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, multiSearchRequest.indicesOptions());
    multiSearchRequest.add(RestActions.getRestContent(request), isTemplateRequest, indices, types, request.param("search_type"), request.param("routing"), indicesOptions, allowExplicitIndex);

    client.multiSearch(multiSearchRequest, new RestToXContentListener<MultiSearchResponse>(channel));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:RestMultiSearchAction.java

示例6: toMultiSearchRequest

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
@Converter
public static MultiSearchRequest toMultiSearchRequest(Object document, Exchange exchange) {
    List<SearchRequest> items = (List<SearchRequest>) document;
    MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
    Iterator<SearchRequest> it = items.iterator();
    while (it.hasNext()) {
        SearchRequest item = it.next();
        multiSearchRequest.add(item);
    }
    return multiSearchRequest;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:ElasticsearchActionRequestConverter.java

示例7: handleRequest

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception {
  MultiSearchRequest multiSearchRequest = new MultiSearchRequest();

  String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
  String[] types = Strings.splitStringByCommaToArray(request.param("type"));
  String path = request.path();
  boolean isTemplateRequest = isTemplateRequest(path);
  IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, multiSearchRequest.indicesOptions());
  multiSearchRequest.add(RestActions.getRestContent(request), isTemplateRequest, indices, types, request.param("search_type"), request.param("routing"), indicesOptions, allowExplicitIndex);

  client.execute(CoordinateMultiSearchAction.INSTANCE, multiSearchRequest, new RestToXContentListener<MultiSearchResponse>(channel));
}
 
开发者ID:sirensolutions,项目名称:siren-join,代码行数:14,代码来源:RestCoordinateMultiSearchAction.java

示例8: toMultiSearchRequest

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
protected MultiSearchRequest toMultiSearchRequest(final RestRequest request) throws Exception {

        final MultiGetRequest multiGetRequest = new MultiGetRequest();
        multiGetRequest.refresh(request.paramAsBoolean("refresh", multiGetRequest.refresh()));
        multiGetRequest.preference(request.param("preference"));
        multiGetRequest.realtime(request.paramAsBoolean("realtime", null));
        multiGetRequest.ignoreErrorsOnGeneratedFields(request.paramAsBoolean("ignore_errors_on_generated_fields", false));

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

        final FetchSourceContext defaultFetchSource = FetchSourceContext.parseFromRestRequest(request);
        multiGetRequest.add(request.param("index"), request.param("type"), sFields, defaultFetchSource, request.param("routing"),
                RestActions.getRestContent(request),
                settings.getAsBoolean(AbstractACRestFilter.REST_ACTION_MULTI_ALLOW_EXPLICIT_INDEX, true));

        final MultiSearchRequest msearch = new MultiSearchRequest();
        msearch.copyContextFrom(request);

        for (final Iterator<Item> iterator = multiGetRequest.iterator(); iterator.hasNext();) {
            final Item item = iterator.next();

            final SearchRequest st = new SearchRequest();
            st.routing(item.routing());
            st.indices(item.indices());
            st.types(item.type());
            st.preference(request.param("preference"));
            st.source(SearchSourceBuilder.searchSource().query(new IdsQueryBuilder(item.type()).addIds(item.id())));
            msearch.add(st);
        }

        return msearch;

    }
 
开发者ID:petalmd,项目名称:armor,代码行数:38,代码来源:AbstractACRestFilter.java

示例9: execute

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
public void execute(MultiSearchRequest request, final ActionListener<MultiSearchResponse> listener) {
    logger.debug("multi search request {}", request);
    try {
        RequestUriBuilder uriBuilder = new RequestUriBuilder();
        uriBuilder.addEndpoint("_msearch");
        uriBuilder.addIndicesOptions(request.indicesOptions());

        // TODO convert lazily
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        for (SearchRequest searchRequest : request.requests()) {
            writeHeader(searchRequest, outputStream);
            outputStream.write(LINE_FEED);
            outputStream.write(searchRequest.source().toBytes());
            outputStream.write(LINE_FEED);
        }

        httpClient.getHttpClient().submit(HttpClientRequest.createPost(uriBuilder.toString())
                .withContent(outputStream.toByteArray()))
                .flatMap(ErrorHandler.AS_FUNC)
                .flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<MultiSearchResponse>>() {
                    @Override
                    public Observable<MultiSearchResponse> call(HttpClientResponse<ByteBuf> response) {
                        return response.getContent().flatMap(new Func1<ByteBuf, Observable<MultiSearchResponse>>() {
                            @Override
                            public Observable<MultiSearchResponse> call(ByteBuf byteBuf) {
                                return MultiSearchResponse.parse(byteBuf);
                            }
                        });
                    }
                })
                .single()
                .subscribe(new ListenerCompleterObserver<>(listener));
    } catch (Exception e) {
        listener.onFailure(e);
    }
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:37,代码来源:MultiSearchActionHandler.java

示例10: should_do_multisearch

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
@Test
public void should_do_multisearch() throws Exception {
    createSimpleDoc(THE_INDEX, THE_TYPE, "1");
    createSimpleDoc(THE_INDEX, THE_TYPE, "2");
    createSimpleDoc(THE_INDEX, THE_TYPE, "3");

    refresh();

    MultiSearchRequest request = new MultiSearchRequest()
            .add(new SearchRequest().indices(THE_INDEX).source(new SearchSourceBuilder().query(matchAllQuery())).searchType(COUNT))
            .add(new SearchRequest().indices(THE_INDEX).source(new SearchSourceBuilder().query(matchQuery("the_string_field", "the_string_value"))))
            .add(new SearchRequest().indices(THE_INDEX).source(new SearchSourceBuilder().query(matchQuery("the_string_field", "the_string_value")).from(1).size(1)))
            ;

    MultiSearchResponse response = httpClient.multiSearch(request).get();

    List<SearchResponse> responses = response.getResponses();
    Assertions.assertThat(responses).hasSize(3);

    Assertions.assertThat(responses.get(0).getHits().getTotal()).isEqualTo(3);
    Assertions.assertThat(responses.get(0).getHits().getHits()).isEmpty();

    Assertions.assertThat(responses.get(1).getHits().getTotal()).isEqualTo(3);
    Assertions.assertThat(responses.get(1).getHits().getHits()).hasSize(3);

    Assertions.assertThat(responses.get(2).getHits().getTotal()).isEqualTo(3);
    Assertions.assertThat(responses.get(2).getHits().getHits()).hasSize(1);
    Assertions.assertThat(responses.get(2).getHits().getHits().get(0).getSource().length).isGreaterThan(1);
}
 
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:30,代码来源:MultiSearchActionHandlerTest.java

示例11: multiSearch

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
@Override
public ActionFuture<MultiSearchResponse> multiSearch(MultiSearchRequest request) {
    return execute(MultiSearchAction.INSTANCE, request);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:AbstractClient.java

示例12: prepareRequest

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    MultiSearchRequest multiSearchRequest = parseRequest(request, allowExplicitIndex);
    return channel -> client.multiSearch(multiSearchRequest, new RestToXContentListener<>(channel));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:RestMultiSearchAction.java

示例13: buildMulti

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
private void buildMulti() {
    multi = new MultiSearchRequest();
    multi.add(firstTable.getRequestBuilder());
    multi.add(secondTable.getRequestBuilder());
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:6,代码来源:JoinRequestBuilder.java

示例14: getMulti

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
public MultiSearchRequest getMulti() {
    return multi;
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:4,代码来源:JoinRequestBuilder.java

示例15: setMulti

import org.elasticsearch.action.search.MultiSearchRequest; //导入依赖的package包/类
public void setMulti(MultiSearchRequest multi) {
    this.multi = multi;
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:4,代码来源:JoinRequestBuilder.java


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