Search in sources :

Example 1 with MultiSearchResponse

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");
}
Also used : MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse) Script(org.elasticsearch.script.Script) ScriptScoreFunctionBuilder(org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder)

Example 2 with MultiSearchResponse

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"));
}
Also used : MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse)

Example 3 with MultiSearchResponse

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"));
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) Before(org.junit.Before)

Example 4 with MultiSearchResponse

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 [[]].");
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) QueryResult(org.graylog.plugins.views.search.QueryResult) SearchError(org.graylog.plugins.views.search.errors.SearchError) Test(org.junit.Test)

Example 5 with MultiSearchResponse

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);
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test)

Aggregations

MultiSearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse)13 Test (org.junit.Test)10 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)8 SearchConfig (org.graylog.plugins.views.search.engine.SearchConfig)8 QueryResult (org.graylog.plugins.views.search.QueryResult)6 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 Arrays (java.util.Arrays)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Provider (javax.inject.Provider)3 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)3 Query (org.graylog.plugins.views.search.Query)3 SearchJob (org.graylog.plugins.views.search.SearchJob)3 SearchType (org.graylog.plugins.views.search.SearchType)3 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)3 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)3 SearchTypeError (org.graylog.plugins.views.search.errors.SearchTypeError)3