Search in sources :

Example 21 with SearchConfig

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

the class ElasticsearchBackendUsingCorrectIndicesTest method queryUsesCorrectTimerangeWhenDeterminingIndexRanges.

@Test
public void queryUsesCorrectTimerangeWhenDeterminingIndexRanges() throws Exception {
    final long datetimeFixture = 1530194810;
    DateTimeUtils.setCurrentMillisFixed(datetimeFixture);
    final ESGeneratedQueryContext context = backend.generate(job, query, new SearchConfig(Period.ZERO));
    backend.doRun(job, query, context);
    ArgumentCaptor<TimeRange> captor = ArgumentCaptor.forClass(TimeRange.class);
    verify(indexLookup, times(1)).indexNamesForStreamsInTimeRange(any(), captor.capture());
    assertThat(captor.getValue()).isEqualTo(RelativeRange.create(600));
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test)

Example 22 with SearchConfig

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

the class ElasticsearchBackendUsingCorrectIndicesTest method queryUsesOnlyIndicesIncludingTimerangeAndStream.

@Test
public void queryUsesOnlyIndicesIncludingTimerangeAndStream() throws Exception {
    final String streamId = "streamId";
    final Query query = dummyQuery(RelativeRange.create(600)).toBuilder().filter(StreamFilter.ofId(streamId)).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("streamId"), 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) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test)

Example 23 with SearchConfig

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

the class ElasticsearchBackendMultiSearchTest method oneFailingSearchTypeReturnsPartialResults.

@Test
public void oneFailingSearchTypeReturnsPartialResults() throws Exception {
    final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
    final MultiSearchResponse response = TestMultisearchResponse.fromFixture("partiallySuccessfulMultiSearchResponse.json");
    final List<MultiSearchResponse.Item> items = Arrays.stream(response.getResponses()).collect(Collectors.toList());
    when(client.msearch(any(), any())).thenReturn(items);
    final QueryResult queryResult = this.elasticsearchBackend.doRun(searchJob, query, queryContext);
    assertThat(queryResult.errors()).hasSize(1);
    final SearchTypeError searchTypeError = (SearchTypeError) new ArrayList<>(queryResult.errors()).get(0);
    assertThat(searchTypeError.description()).isEqualTo("Unable to perform search query: \n" + "\n" + "Elasticsearch exception [type=illegal_argument_exception, reason=Expected numeric type on field [field1], but got [keyword]].");
    assertThat(searchTypeError.searchTypeId()).isEqualTo("pivot1");
    assertThat(queryResult.searchTypes()).containsOnlyKeys("pivot2");
    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) SearchTypeError(org.graylog.plugins.views.search.errors.SearchTypeError) PivotResult(org.graylog.plugins.views.search.searchtypes.pivot.PivotResult) ArrayList(java.util.ArrayList) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test)

Example 24 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));
    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 List<SearchRequest> generatedRequest = run(searchJob, query, queryContext, Collections.emptySet());
    final DocumentContext pivot1 = parse(generatedRequest.get(0).source().toString());
    final DocumentContext pivot2 = parse(generatedRequest.get(1).source().toString());
    assertThat(queryStrings(pivot1)).containsExactly("production:true");
    assertThat(timerangeFrom(pivot1)).containsExactly("2019-09-11 10:31:52.819");
    assertThat(timerangeTo(pivot1)).containsExactly("2019-09-11 10:36:52.823");
    assertThat(streams(pivot1)).containsExactly(Collections.singletonList("stream1"));
    assertThat(queryStrings(pivot2)).containsExactly("production:true", "source:babbage");
    assertThat(timerangeFrom(pivot2)).containsExactly("2018-08-23 08:02:00.247");
    assertThat(timerangeTo(pivot2)).containsExactly("2018-08-23 08:07:00.252");
    assertThat(streams(pivot2)).containsExactly(Collections.singletonList("stream1"));
}
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) DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.Test)

Example 25 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));
    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 List<SearchRequest> generatedRequest = run(searchJob, query, queryContext, Collections.emptySet());
    assertThat(indicesOf(generatedRequest)).hasSize(2).containsExactly("searchTypeIndex", "queryIndex");
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) DerivedTimeRange(org.graylog.plugins.views.search.timeranges.DerivedTimeRange) 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

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