Search in sources :

Example 11 with SearchJob

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

the class ElasticsearchBackendQueryStringDecoratorsTest method searchJobWithSearchTypeQueryString.

private SearchJob searchJobWithSearchTypeQueryString(Query query) throws InvalidRangeParametersException {
    final SearchType searchType = basicSearchType();
    final SearchJob searchJob = basicSearchJob(query, searchType);
    when(query.query()).thenReturn(ElasticsearchQueryString.of("*"));
    when(searchType.query()).thenReturn(Optional.of(ElasticsearchQueryString.of("Should never show up")));
    return searchJob;
}
Also used : SearchJob(org.graylog.plugins.views.search.SearchJob) SearchType(org.graylog.plugins.views.search.SearchType)

Example 12 with SearchJob

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

the class ElasticsearchBackendQueryStringDecoratorsTest method generateAppliesQueryStringDecorators.

@Test
void generateAppliesQueryStringDecorators() throws Exception {
    final Query query = mock(Query.class);
    final SearchJob searchJob = searchJobWithRootQueryString(query);
    final DocumentContext request = generateJsonRequest(query, searchJob);
    assertThat(request).jsonPathAsString(PATH_TO_QUERY_STRING).isEqualTo("decorated");
}
Also used : Query(org.graylog.plugins.views.search.Query) SearchJob(org.graylog.plugins.views.search.SearchJob) DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.jupiter.api.Test)

Example 13 with SearchJob

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

the class ElasticsearchBackendQueryStringDecoratorsTest method generateAppliesQueryStringDecoratorsOnSearchTypes.

@Test
void generateAppliesQueryStringDecoratorsOnSearchTypes() throws Exception {
    final Query query = mock(Query.class);
    final SearchJob searchJob = searchJobWithSearchTypeQueryString(query);
    final DocumentContext request = generateJsonRequest(query, searchJob);
    assertThat(request).jsonPathAsString(PATH_TO_QUERY_STRING).isEqualTo("decorated");
}
Also used : Query(org.graylog.plugins.views.search.Query) SearchJob(org.graylog.plugins.views.search.SearchJob) DocumentContext(com.jayway.jsonpath.DocumentContext) Test(org.junit.jupiter.api.Test)

Example 14 with SearchJob

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

the class ElasticsearchBackendSearchTypesWithStreamsOverridesTest method run.

private MultiSearch run(Query query) throws IOException {
    final SearchJob job = searchJobForQuery(query);
    final ESGeneratedQueryContext context = this.elasticsearchBackend.generate(job, query, new SearchConfig(Period.ZERO));
    this.elasticsearchBackend.doRun(job, query, context);
    verify(jestClient, times(1)).execute(clientRequestCaptor.capture(), any());
    return clientRequestCaptor.getValue();
}
Also used : SearchJob(org.graylog.plugins.views.search.SearchJob) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig)

Example 15 with SearchJob

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

the class ESEventListTest method testSortingOfStreamsInDoExtractResult.

@Test
public void testSortingOfStreamsInDoExtractResult() {
    final ESEventList esEventList = new TestESEventList();
    final SearchJob searchJob = mock(SearchJob.class);
    final Query query = mock(Query.class);
    final SearchResult searchResult = mock(SearchResult.class);
    final MetricAggregation metricAggregation = mock(MetricAggregation.class);
    final ESGeneratedQueryContext queryContext = mock(ESGeneratedQueryContext.class);
    final EventList eventList = EventList.builder().id("search-type-id").streams(ImmutableSet.of("stream-id-1", "stream-id-2")).build();
    final EventList.Result eventResult = (EventList.Result) esEventList.doExtractResult(searchJob, query, eventList, searchResult, metricAggregation, queryContext);
    assertThat(eventResult.events()).containsExactly(eventSummary("find-1", ImmutableSet.of("stream-id-1")), eventSummary("find-2", ImmutableSet.of("stream-id-2")), eventSummary("find-3", ImmutableSet.of("stream-id-1", "stream-id-2")));
}
Also used : Query(org.graylog.plugins.views.search.Query) MetricAggregation(io.searchbox.core.search.aggregation.MetricAggregation) ESEventList(org.graylog.storage.elasticsearch6.views.searchtypes.ESEventList) EventList(org.graylog.plugins.views.search.searchtypes.events.EventList) SearchJob(org.graylog.plugins.views.search.SearchJob) SearchResult(io.searchbox.core.SearchResult) ESEventList(org.graylog.storage.elasticsearch6.views.searchtypes.ESEventList) ESGeneratedQueryContext(org.graylog.storage.elasticsearch6.views.ESGeneratedQueryContext) SearchResult(io.searchbox.core.SearchResult) Test(org.junit.Test)

Aggregations

SearchJob (org.graylog.plugins.views.search.SearchJob)49 Query (org.graylog.plugins.views.search.Query)24 Search (org.graylog.plugins.views.search.Search)24 Test (org.junit.Test)16 SearchType (org.graylog.plugins.views.search.SearchType)13 SearchConfig (org.graylog.plugins.views.search.engine.SearchConfig)12 QueryResult (org.graylog.plugins.views.search.QueryResult)10 Collections (java.util.Collections)9 Set (java.util.Set)9 Collectors (java.util.stream.Collectors)9 List (java.util.List)8 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)8 Optional (java.util.Optional)7 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)7 Message (org.graylog2.plugin.Message)7 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)6 Named (com.google.inject.name.Named)5 MultiSearch (io.searchbox.core.MultiSearch)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5