use of org.elasticsearch.action.search.MultiSearchResponse in project elasticsearch by elastic.
the class TransportTwoNodesSearchIT method testFailedMultiSearchWithWrongQueryWithFunctionScore.
public void testFailedMultiSearchWithWrongQueryWithFunctionScore() throws Exception {
prepareData();
logger.info("Start Testing failed multi search with a wrong query");
MultiSearchResponse response = client().prepareMultiSearch().add(client().prepareSearch("test").setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("nid", 1), new ScriptScoreFunctionBuilder(new Script(ScriptType.INLINE, "bar", "foo", Collections.emptyMap()))))).add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("nid", 2))).add(client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())).execute().actionGet();
assertThat(response.getResponses().length, equalTo(3));
assertThat(response.getResponses()[0].getFailureMessage(), notNullValue());
assertThat(response.getResponses()[1].getFailureMessage(), nullValue());
assertThat(response.getResponses()[1].getResponse().getHits().getHits().length, equalTo(1));
assertThat(response.getResponses()[2].getFailureMessage(), nullValue());
assertThat(response.getResponses()[2].getResponse().getHits().getHits().length, equalTo(10));
logger.info("Done Testing failed search");
}
use of org.elasticsearch.action.search.MultiSearchResponse in project elasticsearch by elastic.
the class MultiSearchIT method testSimpleMultiSearch.
public void testSimpleMultiSearch() {
createIndex("test");
ensureGreen();
client().prepareIndex("test", "type", "1").setSource("field", "xxx").execute().actionGet();
client().prepareIndex("test", "type", "2").setSource("field", "yyy").execute().actionGet();
refresh();
MultiSearchResponse response = client().prepareMultiSearch().add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "xxx"))).add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "yyy"))).add(client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())).execute().actionGet();
for (MultiSearchResponse.Item item : response) {
assertNoFailures(item.getResponse());
}
assertThat(response.getResponses().length, equalTo(3));
assertHitCount(response.getResponses()[0].getResponse(), 1L);
assertHitCount(response.getResponses()[1].getResponse(), 1L);
assertHitCount(response.getResponses()[2].getResponse(), 2L);
assertFirstHit(response.getResponses()[0].getResponse(), hasId("1"));
assertFirstHit(response.getResponses()[1].getResponse(), hasId("2"));
}
use of org.elasticsearch.action.search.MultiSearchResponse in project graylog2-server by Graylog2.
the class ElasticsearchBackendSearchTypesWithStreamsOverridesTest method setUp.
@Before
public void setUp() throws Exception {
final MultiSearchResponse response = TestMultisearchResponse.fromFixture("successfulMultiSearchResponse.json");
final List<MultiSearchResponse.Item> items = Arrays.stream(response.getResponses()).collect(Collectors.toList());
when(client.msearch(any(), any())).thenReturn(items);
when(indexLookup.indexNamesForStreamsInTimeRange(eq(ImmutableSet.of(stream1Id)), any())).thenReturn(ImmutableSet.of("index1", "index2"));
when(indexLookup.indexNamesForStreamsInTimeRange(eq(ImmutableSet.of(stream2Id)), any())).thenReturn(ImmutableSet.of("index3"));
}
use of org.elasticsearch.action.search.MultiSearchResponse in project graylog2-server by Graylog2.
the class ElasticsearchBackendErrorHandlingTest method deduplicateShardErrorsOnSearchTypeLevel.
@Test
public void deduplicateShardErrorsOnSearchTypeLevel() throws IOException {
final MultiSearchResponse multiSearchResult = TestMultisearchResponse.fromFixture("errorhandling/failureOnSearchTypeLevel.json");
final List<MultiSearchResponse.Item> items = Arrays.stream(multiSearchResult.getResponses()).collect(Collectors.toList());
when(client.msearch(any(), any())).thenReturn(items);
final QueryResult queryResult = this.backend.doRun(searchJob, query, queryContext);
final Set<SearchError> errors = queryResult.errors();
assertThat(errors).isNotNull();
assertThat(errors).hasSize(1);
assertThat(errors.stream().map(SearchError::description).collect(Collectors.toList())).containsExactly("Unable to perform search query: " + "\n\nElasticsearch exception [type=query_shard_exception, reason=Failed to parse query [[]].");
}
use of org.elasticsearch.action.search.MultiSearchResponse in project graylog2-server by Graylog2.
the class ElasticsearchBackendMultiSearchTest method everySearchTypeGeneratesOneESQuery.
@Test
public void everySearchTypeGeneratesOneESQuery() throws Exception {
final MultiSearchResponse response = TestMultisearchResponse.fromFixture("successfulMultiSearchResponse.json");
final List<MultiSearchResponse.Item> items = Arrays.stream(response.getResponses()).collect(Collectors.toList());
when(client.msearch(any(), any())).thenReturn(items);
final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
final List<SearchRequest> generatedRequest = run(searchJob, query, queryContext, Collections.emptySet());
assertThat(generatedRequest).hasSize(2);
}
Aggregations