Search in sources :

Example 1 with MultiSearch

use of io.searchbox.core.MultiSearch in project graylog2-server by Graylog2.

the class ElasticsearchBackendUsingCorrectIndicesTest method queryDoesNotFallBackToUsingAllIndicesWhenNoIndexRangesAreReturned.

@Test
public void queryDoesNotFallBackToUsingAllIndicesWhenNoIndexRangesAreReturned() throws Exception {
    final ESGeneratedQueryContext context = backend.generate(job, query, new SearchConfig(Period.ZERO));
    backend.doRun(job, query, context);
    verify(jestClient, times(1)).execute(clientRequestCaptor.capture(), any());
    final MultiSearch clientRequest = clientRequestCaptor.getValue();
    assertThat(clientRequest).isNotNull();
    assertThat(indicesOf(clientRequest).get(0)).isEqualTo("");
}
Also used : SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) MultiSearch(io.searchbox.core.MultiSearch) Test(org.junit.Test)

Example 2 with MultiSearch

use of io.searchbox.core.MultiSearch in project graylog2-server by Graylog2.

the class ElasticsearchBackendUsingCorrectIndicesTest method queryUsesOnlyIndicesBelongingToStream.

@Test
public void queryUsesOnlyIndicesBelongingToStream() throws Exception {
    final Query query = dummyQuery(RelativeRange.create(600)).toBuilder().filter(AndFilter.and(StreamFilter.ofId("stream1"), StreamFilter.ofId("stream2"))).build();
    final Search search = dummySearch(query);
    final SearchJob job = new SearchJob("job1", search, "admin");
    final ESGeneratedQueryContext context = backend.generate(job, query, new SearchConfig(Period.ZERO));
    when(indexLookup.indexNamesForStreamsInTimeRange(ImmutableSet.of("stream1", "stream2"), RelativeRange.create(600))).thenReturn(ImmutableSet.of("index1", "index2"));
    backend.doRun(job, query, context);
    verify(jestClient, times(1)).execute(clientRequestCaptor.capture(), any());
    final MultiSearch clientRequest = clientRequestCaptor.getValue();
    assertThat(clientRequest).isNotNull();
    assertThat(indicesOf(clientRequest).get(0)).isEqualTo("index1,index2");
}
Also used : Query(org.graylog.plugins.views.search.Query) Search(org.graylog.plugins.views.search.Search) MultiSearch(io.searchbox.core.MultiSearch) SearchJob(org.graylog.plugins.views.search.SearchJob) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) MultiSearch(io.searchbox.core.MultiSearch) Test(org.junit.Test)

Example 3 with MultiSearch

use of io.searchbox.core.MultiSearch in project graylog2-server by Graylog2.

the class ElasticsearchBackendSearchTypesWithStreamsOverridesTest method searchTypeWithoutStreamsDefaultsToQueriesStreams.

@Test
public void searchTypeWithoutStreamsDefaultsToQueriesStreams() throws IOException {
    final Query query = queryFor(Pivot.builder().id("pivot1").series(Collections.singletonList(Average.builder().field("field1").build())).rollup(true).build());
    final MultiSearch request = run(query);
    assertThat(indicesOf(request).get(0)).isEqualTo("index1,index2");
}
Also used : Query(org.graylog.plugins.views.search.Query) MultiSearch(io.searchbox.core.MultiSearch) Test(org.junit.Test)

Example 4 with MultiSearch

use of io.searchbox.core.MultiSearch in project graylog2-server by Graylog2.

the class CountsAdapterES6 method totalCount.

@Override
public long totalCount(List<String> indices) {
    final String query = new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).size(0).toString();
    final Search request = new Search.Builder(query).addIndex(indices).build();
    final MultiSearch multiSearch = new MultiSearch.Builder(request).build();
    final MultiSearchResult searchResult = JestUtils.execute(jestClient, multiSearch, () -> "Fetching message count failed for indices " + indices);
    final List<MultiSearchResult.MultiSearchResponse> responses = searchResult.getResponses();
    long total = 0L;
    for (MultiSearchResult.MultiSearchResponse response : responses) {
        if (response.isError) {
            throw JestUtils.specificException(() -> "Fetching message count failed for indices " + indices, response.error);
        }
        total += response.searchResult.getTotal();
    }
    return total;
}
Also used : MultiSearchResult(io.searchbox.core.MultiSearchResult) MultiSearch(io.searchbox.core.MultiSearch) Search(io.searchbox.core.Search) SearchSourceBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) MultiSearch(io.searchbox.core.MultiSearch) SearchSourceBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder)

Example 5 with MultiSearch

use of io.searchbox.core.MultiSearch in project graylog2-server by Graylog2.

the class ElasticsearchBackendSearchTypesWithStreamsOverridesTest method searchTypeWithEmptyStreamsDefaultsToQueriesStreams.

@Test
public void searchTypeWithEmptyStreamsDefaultsToQueriesStreams() throws IOException {
    final Query query = queryFor(Pivot.builder().id("pivot1").series(Collections.singletonList(Average.builder().field("field1").build())).rollup(true).streams(Collections.emptySet()).build());
    final MultiSearch request = run(query);
    assertThat(indicesOf(request).get(0)).isEqualTo("index1,index2");
}
Also used : Query(org.graylog.plugins.views.search.Query) MultiSearch(io.searchbox.core.MultiSearch) Test(org.junit.Test)

Aggregations

MultiSearch (io.searchbox.core.MultiSearch)9 Test (org.junit.Test)7 Query (org.graylog.plugins.views.search.Query)6 SearchConfig (org.graylog.plugins.views.search.engine.SearchConfig)3 Search (org.graylog.plugins.views.search.Search)2 SearchJob (org.graylog.plugins.views.search.SearchJob)2 MultiSearchResult (io.searchbox.core.MultiSearchResult)1 Search (io.searchbox.core.Search)1 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)1 SearchSourceBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder)1