Search in sources :

Example 1 with MultiSearchRequestBuilder

use of org.elasticsearch.action.search.MultiSearchRequestBuilder in project elasticsearch by elastic.

the class IndicesOptionsIntegrationIT method verify.

private static void verify(ActionRequestBuilder requestBuilder, boolean fail, long expectedCount) {
    if (fail) {
        if (requestBuilder instanceof MultiSearchRequestBuilder) {
            MultiSearchResponse multiSearchResponse = ((MultiSearchRequestBuilder) requestBuilder).get();
            assertThat(multiSearchResponse.getResponses().length, equalTo(1));
            assertThat(multiSearchResponse.getResponses()[0].isFailure(), is(true));
            assertThat(multiSearchResponse.getResponses()[0].getResponse(), nullValue());
        } else {
            try {
                requestBuilder.get();
                fail("IndexNotFoundException or IndexClosedException was expected");
            } catch (IndexNotFoundException | IndexClosedException e) {
            }
        }
    } else {
        if (requestBuilder instanceof SearchRequestBuilder) {
            SearchRequestBuilder searchRequestBuilder = (SearchRequestBuilder) requestBuilder;
            assertHitCount(searchRequestBuilder.get(), expectedCount);
        } else if (requestBuilder instanceof MultiSearchRequestBuilder) {
            MultiSearchResponse multiSearchResponse = ((MultiSearchRequestBuilder) requestBuilder).get();
            assertThat(multiSearchResponse.getResponses().length, equalTo(1));
            assertThat(multiSearchResponse.getResponses()[0].getResponse(), notNullValue());
        } else {
            requestBuilder.get();
        }
    }
}
Also used : MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse) MultiSearchRequestBuilder(org.elasticsearch.action.search.MultiSearchRequestBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) MultiSearchRequestBuilder(org.elasticsearch.action.search.MultiSearchRequestBuilder)

Aggregations

MultiSearchRequestBuilder (org.elasticsearch.action.search.MultiSearchRequestBuilder)1 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)1