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");
}
use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class ElasticsearchBackendSearchTypesWithStreamsOverridesTest method run.
private List<SearchRequest> 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(client, times(1)).msearch(clientRequestCaptor.capture(), any());
return clientRequestCaptor.getValue();
}
use of org.graylog.plugins.views.search.SearchJob 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");
}
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 SearchResponse searchResult = mock(SearchResponse.class);
final Aggregations metricAggregation = mock(Aggregations.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")));
}
use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class ElasticsearchBackendErrorHandlingTest method setUp.
@Before
public void setUp() throws Exception {
final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
this.backend = new ElasticsearchBackend(ImmutableMap.of("dummy", () -> mock(DummyHandler.class)), client, indexLookup, new QueryStringDecorators(Collections.emptySet()), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false);
when(indexLookup.indexNamesForStreamsInTimeRange(any(), any())).thenReturn(Collections.emptySet());
final SearchType searchType1 = mock(SearchType.class);
when(searchType1.id()).thenReturn("deadbeef");
when(searchType1.type()).thenReturn("dummy");
final SearchType searchType2 = mock(SearchType.class);
when(searchType2.id()).thenReturn("cafeaffe");
when(searchType2.type()).thenReturn("dummy");
final Set<SearchType> searchTypes = ImmutableSet.of(searchType1, searchType2);
this.query = Query.builder().id("query1").timerange(RelativeRange.create(300)).query(ElasticsearchQueryString.of("*")).searchTypes(searchTypes).build();
final Search search = Search.builder().id("search1").queries(ImmutableSet.of(query)).build();
this.searchJob = new SearchJob("job1", search, "admin");
this.queryContext = new ESGeneratedQueryContext(this.backend, new SearchSourceBuilder(), searchJob, query, mock(FieldTypesLookup.class));
searchTypes.forEach(queryContext::searchSourceBuilder);
}
Aggregations