use of org.elasticsearch.action.search.MultiSearchResponse 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();
}
}
}
use of org.elasticsearch.action.search.MultiSearchResponse in project camel by apache.
the class ElasticsearchGetSearchDeleteExistsUpdateTest method testMultiSearch.
@Test
public void testMultiSearch() throws Exception {
//first, INDEX two values
Map<String, Object> headers = new HashMap<String, Object>();
node.client().prepareIndex("test", "type", "1").setSource("field", "xxx").execute().actionGet();
node.client().prepareIndex("test", "type", "2").setSource("field", "yyy").execute().actionGet();
//now, verify MULTISEARCH
headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.MULTISEARCH);
SearchRequestBuilder srb1 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "xxx"));
SearchRequestBuilder srb2 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "yyy"));
SearchRequestBuilder srb3 = node.client().prepareSearch("instagram").setTypes("type").setQuery(QueryBuilders.termQuery("test-multisearchkey", "test-multisearchvalue"));
List<SearchRequest> list = new ArrayList<>();
list.add(srb1.request());
list.add(srb2.request());
list.add(srb3.request());
MultiSearchResponse response = template.requestBodyAndHeaders("direct:multisearch", list, headers, MultiSearchResponse.class);
MultiSearchResponse.Item[] responses = response.getResponses();
assertNotNull("response should not be null", response);
assertEquals("response should contains three multiSearchResponse object", 3, response.getResponses().length);
assertFalse("response 1 should be ok", responses[0].isFailure());
assertFalse("response 2 should be ok", responses[1].isFailure());
assertTrue("response 3 should be failed", responses[2].isFailure());
}
use of org.elasticsearch.action.search.MultiSearchResponse in project camel by apache.
the class ElasticsearchGetSearchDeleteExistsUpdateTest method testMultiSearch.
@Test
public void testMultiSearch() throws Exception {
//first, INDEX two values
Map<String, Object> headers = new HashMap<String, Object>();
node.client().prepareIndex("test", "type", "1").setSource("field", "xxx").execute().actionGet();
node.client().prepareIndex("test", "type", "2").setSource("field", "yyy").execute().actionGet();
//now, verify MULTISEARCH
headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_MULTISEARCH);
SearchRequestBuilder srb1 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "xxx"));
SearchRequestBuilder srb2 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "yyy"));
SearchRequestBuilder srb3 = node.client().prepareSearch("instagram").setTypes("type").setQuery(QueryBuilders.termQuery("test-multisearchkey", "test-multisearchvalue"));
List<SearchRequest> list = new ArrayList<>();
list.add(srb1.request());
list.add(srb2.request());
list.add(srb3.request());
MultiSearchResponse response = template.requestBodyAndHeaders("direct:multisearch", list, headers, MultiSearchResponse.class);
MultiSearchResponse.Item[] responses = response.getResponses();
assertNotNull("response should not be null", response);
assertEquals("response should contains three multiSearchResponse object", 3, response.getResponses().length);
assertFalse("response 1 should be ok", responses[0].isFailure());
assertFalse("response 2 should be ok", responses[1].isFailure());
assertTrue("response 3 should be failed", responses[2].isFailure());
}
Aggregations