Search in sources :

Example 71 with SearchRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest 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(client, times(1)).msearch(clientRequestCaptor.capture(), any());
    final List<SearchRequest> clientRequest = clientRequestCaptor.getValue();
    assertThat(clientRequest).isNotNull();
    assertThat(indicesOf(clientRequest).get(0)).isEqualTo("");
}
Also used : SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test)

Example 72 with SearchRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest 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(client, times(1)).msearch(clientRequestCaptor.capture(), any());
    final List<SearchRequest> clientRequest = clientRequestCaptor.getValue();
    assertThat(clientRequest).isNotNull();
    assertThat(indicesOf(clientRequest).get(0)).isEqualTo("index1,index2");
}
Also used : SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) Query(org.graylog.plugins.views.search.Query) Search(org.graylog.plugins.views.search.Search) SearchJob(org.graylog.plugins.views.search.SearchJob) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test)

Example 73 with SearchRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest 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 List<SearchRequest> request = run(query);
    assertThat(indicesOf(request).get(0)).isEqualTo("index1,index2");
}
Also used : SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) Query(org.graylog.plugins.views.search.Query) Test(org.junit.Test)

Example 74 with SearchRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest 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)

Example 75 with SearchRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project graylog2-server by Graylog2.

the class CountsAdapterES7 method totalCount.

@Override
public long totalCount(List<String> indices) {
    final SearchSourceBuilder query = new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).size(0).trackTotalHits(true);
    final SearchRequest searchRequest = new SearchRequest(indices.toArray(new String[0])).source(query);
    final SearchResponse result = client.search(searchRequest, "Fetching message count failed for indices ");
    return result.getHits().getTotalHits().value;
}
Also used : SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) SearchSourceBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder) SearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse)

Aggregations

SearchRequest (org.elasticsearch.action.search.SearchRequest)156 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)81 SearchResponse (org.elasticsearch.action.search.SearchResponse)69 Test (org.junit.Test)37 IOException (java.io.IOException)31 SearchHit (org.elasticsearch.search.SearchHit)25 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)22 ArrayList (java.util.ArrayList)21 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)21 HashMap (java.util.HashMap)18 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)17 List (java.util.List)16 SearchHits (org.elasticsearch.search.SearchHits)15 Pipeline (com.hazelcast.jet.pipeline.Pipeline)14 Map (java.util.Map)13 Matchers.containsString (org.hamcrest.Matchers.containsString)12 SearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse)11 SearchSourceBuilder (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder)11 QueryBuilders (org.elasticsearch.index.query.QueryBuilders)10 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)10