use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class ElasticsearchBackendQueryStringDecoratorsTest method basicSearchJob.
@Nonnull
private SearchJob basicSearchJob(Query query, SearchType searchType) throws InvalidRangeParametersException {
final SearchJob searchJob = mock(SearchJob.class);
final Search search = mock(Search.class);
when(searchJob.getSearch()).thenReturn(search);
when(search.queries()).thenReturn(ImmutableSet.of(query));
when(query.effectiveTimeRange(any())).thenReturn(RelativeRange.create(300));
when(query.searchTypes()).thenReturn(ImmutableSet.of(searchType));
return searchJob;
}
use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class ElasticsearchBackendTest method executesSearchForEmptySearchTypes.
@Test
public void executesSearchForEmptySearchTypes() throws Exception {
final Query query = Query.builder().id("query1").query(ElasticsearchQueryString.of("")).timerange(RelativeRange.create(300)).build();
final Search search = Search.builder().queries(ImmutableSet.of(query)).build();
final SearchJob job = new SearchJob("deadbeef", search, "admin");
final ESGeneratedQueryContext queryContext = mock(ESGeneratedQueryContext.class);
final QueryResult queryResult = backend.doRun(job, query, queryContext);
assertThat(queryResult).isNotNull();
assertThat(queryResult.searchTypes()).isEmpty();
assertThat(queryResult.executionStats()).isNotNull();
assertThat(queryResult.errors()).isEmpty();
}
use of org.graylog.plugins.views.search.SearchJob in project graylog2-server by Graylog2.
the class ElasticsearchBackendUsingCorrectIndicesTest method before.
@Before
public void before() throws Exception {
this.query = Query.builder().id("query1").timerange(RelativeRange.create(600)).query(ElasticsearchQueryString.of("*")).searchTypes(ImmutableSet.of(MessageList.builder().id("1").build())).build();
final Search search = Search.builder().id("search1").queries(ImmutableSet.of(query)).build();
this.job = new SearchJob("job1", search, "admin");
}
use of org.graylog.plugins.views.search.SearchJob 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");
}
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)), jestClient, indexLookup, new QueryStringDecorators(Collections.emptySet()), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false, objectMapper);
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);
when(jestClient.execute(any())).thenReturn(result);
}
Aggregations