Search in sources :

Example 1 with QueryStringDecorators

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

the class ElasticsearchBackendQueryStringDecoratorsTest method setUp.

@BeforeEach
void setUp() {
    final QueryStringDecorator decorator = (queryString, job, query) -> "decorated";
    final Set<QueryStringDecorator> decorators = Collections.singleton(decorator);
    final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
    this.backend = new ElasticsearchBackend(Collections.emptyMap(), mock(ElasticsearchClient.class), mock(IndexLookup.class), new QueryStringDecorators(decorators), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), true);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) Query(org.graylog.plugins.views.search.Query) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) SearchType(org.graylog.plugins.views.search.SearchType) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) Search(org.graylog.plugins.views.search.Search) Nonnull(javax.annotation.Nonnull) JsonPathAssert.assertThat(com.revinate.assertj.json.JsonPathAssert.assertThat) Period(org.joda.time.Period) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.jupiter.api.Test) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) DocumentContext(com.jayway.jsonpath.DocumentContext) Optional(java.util.Optional) 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) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 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 3 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 org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse result = mock(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse.class);
    when(result.getHits()).thenReturn(SearchHits.empty());
    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) SearchType(org.graylog.plugins.views.search.SearchType) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) Test(org.junit.Test)

Example 4 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)), 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);
}
Also used : ESSearchTypeHandler(org.graylog.storage.elasticsearch6.views.searchtypes.ESSearchTypeHandler) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Query(org.graylog.plugins.views.search.Query) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultiSearchResult(io.searchbox.core.MultiSearchResult) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) JestClient(io.searchbox.client.JestClient) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) SearchType(org.graylog.plugins.views.search.SearchType) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) MockitoJUnit(org.mockito.junit.MockitoJUnit) JsonNode(com.fasterxml.jackson.databind.JsonNode) 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) 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) 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) SearchSourceBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) 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.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) Before(org.junit.Before)

Example 5 with QueryStringDecorators

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

the class ElasticsearchBackendQueryStringDecoratorsTest method setUp.

@BeforeEach
void setUp() {
    final QueryStringDecorator decorator = (queryString, job, query) -> "decorated";
    final Set<QueryStringDecorator> decorators = Collections.singleton(decorator);
    final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
    this.backend = new ElasticsearchBackend(Collections.emptyMap(), mock(JestClient.class), mock(IndexLookup.class), new QueryStringDecorators(decorators), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), true, new ObjectMapperProvider().get());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) Query(org.graylog.plugins.views.search.Query) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) JestClient(io.searchbox.client.JestClient) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) SearchType(org.graylog.plugins.views.search.SearchType) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) Search(org.graylog.plugins.views.search.Search) Nonnull(javax.annotation.Nonnull) JsonPathAssert.assertThat(com.revinate.assertj.json.JsonPathAssert.assertThat) Period(org.joda.time.Period) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) JsonPath(com.jayway.jsonpath.JsonPath) Test(org.junit.jupiter.api.Test) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) DocumentContext(com.jayway.jsonpath.DocumentContext) Optional(java.util.Optional) 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) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

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