Search in sources :

Example 6 with QueryStringDecorators

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

the class ESMessageListTest method includesCustomNameInResultIfPresent.

@Test
public void includesCustomNameInResultIfPresent() {
    final ESMessageList esMessageList = new ESMessageList(new QueryStringDecorators(Collections.emptySet()));
    final MessageList messageList = someMessageList().toBuilder().name("customResult").build();
    final SearchResult result = new MockSearchResult(Collections.emptyList(), (long) 0);
    final SearchType.Result searchTypeResult = esMessageList.doExtractResult(null, someQuery(), messageList, result, null, null);
    assertThat(searchTypeResult.name()).contains("customResult");
}
Also used : QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) SearchResult(io.searchbox.core.SearchResult) SearchType(org.graylog.plugins.views.search.SearchType) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) Test(org.junit.Test)

Example 7 with QueryStringDecorators

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

the class MessagesResourceTest method setUp.

@BeforeEach
void setUp() {
    GuiceInjectorHolder.createInjector(Collections.emptyList());
    currentUser = mock(User.class);
    when(currentUser.getName()).thenReturn("peterchen");
    MessagesExporter exporter = mock(MessagesExporter.class);
    commandFactory = mock(CommandFactory.class);
    when(commandFactory.buildFromRequest(any())).thenReturn(ExportMessagesCommand.withDefaults());
    when(commandFactory.buildWithSearchOnly(any(), any())).thenReturn(ExportMessagesCommand.withDefaults());
    when(commandFactory.buildWithMessageList(any(), any(), any())).thenReturn(ExportMessagesCommand.withDefaults());
    permittedStreams = mock(PermittedStreams.class);
    when(permittedStreams.load(any())).thenReturn(ImmutableSet.of("a-default-stream"));
    executionGuard = mock(SearchExecutionGuard.class);
    SearchDomain searchDomain = mock(SearchDomain.class);
    final QueryValidationServiceImpl validationService = new QueryValidationServiceImpl(new LuceneQueryParser(), (streamIds, timeRange) -> Collections.emptySet(), new QueryStringDecorators(Collections.emptySet()));
    sut = new MessagesTestResource(exporter, commandFactory, searchDomain, executionGuard, permittedStreams, mock(ObjectMapper.class), eventBus, validationService);
    sut.asyncRunner = c -> {
        c.accept(x -> {
        });
        return null;
    };
}
Also used : SearchUser(org.graylog.plugins.views.search.permissions.SearchUser) User(org.graylog2.plugin.database.users.User) QueryValidationServiceImpl(org.graylog.plugins.views.search.validation.QueryValidationServiceImpl) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) SearchDomain(org.graylog.plugins.views.search.SearchDomain) MessagesExporter(org.graylog.plugins.views.search.export.MessagesExporter) CommandFactory(org.graylog.plugins.views.search.export.CommandFactory) SearchExecutionGuard(org.graylog.plugins.views.search.SearchExecutionGuard) LuceneQueryParser(org.graylog.plugins.views.search.validation.LuceneQueryParser) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with QueryStringDecorators

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

the class ESMessageListTest method generateQueryPartWithContextFor.

private ESGeneratedQueryContext generateQueryPartWithContextFor(MessageList messageList, boolean allowHighlighting, Set<QueryStringDecorator> decorators, ESGeneratedQueryContext context) {
    ESMessageList sut = new ESMessageList(new QueryStringDecorators(decorators), new LegacyDecoratorProcessor.Fake(), allowHighlighting);
    sut.doGenerateQueryPart(mock(SearchJob.class), someQuery(), messageList, context);
    return context;
}
Also used : LegacyDecoratorProcessor(org.graylog.plugins.views.search.LegacyDecoratorProcessor) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) SearchJob(org.graylog.plugins.views.search.SearchJob)

Example 9 with QueryStringDecorators

use of org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators 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);
}
Also used : ESSearchTypeHandler(org.graylog.storage.elasticsearch7.views.searchtypes.ESSearchTypeHandler) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) Arrays(java.util.Arrays) Query(org.graylog.plugins.views.search.Query) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) SearchType(org.graylog.plugins.views.search.SearchType) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) MockitoJUnit(org.mockito.junit.MockitoJUnit) Search(org.graylog.plugins.views.search.Search) QueryResult(org.graylog.plugins.views.search.QueryResult) Before(org.junit.Before) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) SearchSourceBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder) TestMultisearchResponse(org.graylog.storage.elasticsearch7.testing.TestMultisearchResponse) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) List(java.util.List) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Rule(org.junit.Rule) SearchError(org.graylog.plugins.views.search.errors.SearchError) MockitoRule(org.mockito.junit.MockitoRule) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Search(org.graylog.plugins.views.search.Search) SearchJob(org.graylog.plugins.views.search.SearchJob) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) SearchType(org.graylog.plugins.views.search.SearchType) SearchSourceBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder) Before(org.junit.Before)

Aggregations

QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)9 SearchJob (org.graylog.plugins.views.search.SearchJob)6 SearchType (org.graylog.plugins.views.search.SearchType)6 ImmutableSet (com.google.common.collect.ImmutableSet)4 Collections (java.util.Collections)4 Set (java.util.Set)4 Query (org.graylog.plugins.views.search.Query)4 Search (org.graylog.plugins.views.search.Search)4 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)4 FieldTypesLookup (org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup)4 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)4 RelativeRange (org.graylog2.plugin.indexer.searches.timeranges.RelativeRange)4 Test (org.junit.Test)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Mockito.mock (org.mockito.Mockito.mock)3 Mockito.when (org.mockito.Mockito.when)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 DocumentContext (com.jayway.jsonpath.DocumentContext)2 JsonPath (com.jayway.jsonpath.JsonPath)2