Search in sources :

Example 6 with SearchConfig

use of org.graylog.plugins.views.search.engine.SearchConfig in project graylog2-server by Graylog2.

the class ElasticsearchBackendMultiSearchTest method multiSearchResultsAreAssignedToSearchTypes.

@Test
public void multiSearchResultsAreAssignedToSearchTypes() 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 QueryResult queryResult = this.elasticsearchBackend.doRun(searchJob, query, queryContext);
    assertThat(queryResult.searchTypes()).containsOnlyKeys("pivot1", "pivot2");
    final PivotResult pivot1Result = (PivotResult) queryResult.searchTypes().get("pivot1");
    assertThat(pivot1Result.rows().get(0)).isEqualTo(PivotResult.Row.builder().key(ImmutableList.of()).source("leaf").addValue(PivotResult.Value.create(Collections.singletonList("avg(field1)"), 27220.273504273504, true, "row-leaf")).build());
    final PivotResult pivot2Result = (PivotResult) queryResult.searchTypes().get("pivot2");
    assertThat(pivot2Result.rows().get(0)).isEqualTo(PivotResult.Row.builder().key(ImmutableList.of()).source("leaf").addValue(PivotResult.Value.create(Collections.singletonList("max(field2)"), 42.0, true, "row-leaf")).build());
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) QueryResult(org.graylog.plugins.views.search.QueryResult) PivotResult(org.graylog.plugins.views.search.searchtypes.pivot.PivotResult) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test)

Example 7 with SearchConfig

use of org.graylog.plugins.views.search.engine.SearchConfig in project graylog2-server by Graylog2.

the class ElasticsearchBackendSearchTypeOverridesTest method timerangeOverridesAffectIndicesSelection.

@Test
public void timerangeOverridesAffectIndicesSelection() throws IOException, InvalidRangeParametersException {
    when(indexLookup.indexNamesForStreamsInTimeRange(ImmutableSet.of("stream1"), timeRangeForTest())).thenReturn(ImmutableSet.of("queryIndex"));
    TimeRange tr = AbsoluteRange.create("2019-09-11T10:31:52.819Z", "2019-09-11T10:36:52.823Z");
    when(indexLookup.indexNamesForStreamsInTimeRange(ImmutableSet.of("stream1"), tr)).thenReturn(ImmutableSet.of("searchTypeIndex"));
    final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
    when(jestClient.execute(any(), any())).thenReturn(resultFor(resourceFile("successfulMultiSearchResponse.json")));
    final String generatedRequest = run(searchJob, query, queryContext, Collections.emptySet());
    assertThat(generatedRequest).isEqualTo(resourceFile("timerangeOverridesAffectIndicesSelection.request.ndjson"));
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) DerivedTimeRange(org.graylog.plugins.views.search.timeranges.DerivedTimeRange) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) Test(org.junit.Test)

Example 8 with SearchConfig

use of org.graylog.plugins.views.search.engine.SearchConfig in project graylog2-server by Graylog2.

the class ElasticsearchBackendSearchTypeOverridesTest method overridesInSearchTypeAreIncorporatedIntoGeneratedQueries.

@Test
public void overridesInSearchTypeAreIncorporatedIntoGeneratedQueries() throws IOException {
    final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
    when(jestClient.execute(any(), any())).thenReturn(resultFor(resourceFile("successfulMultiSearchResponse.json")));
    final String generatedRequest = run(searchJob, query, queryContext, Collections.emptySet());
    assertThat(generatedRequest).isEqualTo(resourceFile("overridesInSearchTypeAreIncorporatedIntoGeneratedQueries.request.ndjson"));
}
Also used : SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) Test(org.junit.Test)

Example 9 with SearchConfig

use of org.graylog.plugins.views.search.engine.SearchConfig 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 10 with SearchConfig

use of org.graylog.plugins.views.search.engine.SearchConfig 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)

Aggregations

SearchConfig (org.graylog.plugins.views.search.engine.SearchConfig)26 Test (org.junit.Test)22 SearchJob (org.graylog.plugins.views.search.SearchJob)8 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)7 Query (org.graylog.plugins.views.search.Query)6 Search (org.graylog.plugins.views.search.Search)6 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)6 MultiSearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse)5 QueryResult (org.graylog.plugins.views.search.QueryResult)4 PivotResult (org.graylog.plugins.views.search.searchtypes.pivot.PivotResult)4 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)4 MultiSearch (io.searchbox.core.MultiSearch)3 ArrayList (java.util.ArrayList)2 SearchTypeError (org.graylog.plugins.views.search.errors.SearchTypeError)2 DerivedTimeRange (org.graylog.plugins.views.search.timeranges.DerivedTimeRange)2 DocumentContext (com.jayway.jsonpath.DocumentContext)1