Search in sources :

Example 21 with ESGeneratedQueryContext

use of org.graylog.storage.elasticsearch6.views.ESGeneratedQueryContext 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")));
}
Also used : Query(org.graylog.plugins.views.search.Query) EventList(org.graylog.plugins.views.search.searchtypes.events.EventList) ESEventList(org.graylog.storage.elasticsearch7.views.searchtypes.ESEventList) Aggregations(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregations) SearchJob(org.graylog.plugins.views.search.SearchJob) ESEventList(org.graylog.storage.elasticsearch7.views.searchtypes.ESEventList) ESGeneratedQueryContext(org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext) SearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse) Test(org.junit.Test)

Example 22 with ESGeneratedQueryContext

use of org.graylog.storage.elasticsearch6.views.ESGeneratedQueryContext in project graylog2-server by Graylog2.

the class ESMessageListTest method mockQueryContext.

private ESGeneratedQueryContext mockQueryContext(MessageList messageList) {
    ESGeneratedQueryContext context = mock(ESGeneratedQueryContext.class);
    when(context.searchSourceBuilder(messageList)).thenReturn(new SearchSourceBuilder());
    return context;
}
Also used : ESGeneratedQueryContext(org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext) SearchSourceBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder)

Example 23 with ESGeneratedQueryContext

use of org.graylog.storage.elasticsearch6.views.ESGeneratedQueryContext in project graylog2-server by Graylog2.

the class ESMessageListTest method appliesDecoratorsToQueryStringIfHighlightingActivated.

@Test
public void appliesDecoratorsToQueryStringIfHighlightingActivated() {
    final QueryStringDecorator queryStringDecorator = (String queryString, ParameterProvider job, Query query) -> "Foobar!";
    final MessageList messageList = someMessageList();
    ESGeneratedQueryContext queryContext = generateQueryPartWithHighlighting(messageList, Collections.singleton(queryStringDecorator));
    final DocumentContext doc = JsonPath.parse(queryContext.searchSourceBuilder(messageList).toString());
    JsonPathAssert.assertThat(doc).jsonPathAsString("$.highlight.highlight_query.query_string.query").isEqualTo("Foobar!");
}
Also used : ParameterProvider(org.graylog.plugins.views.search.ParameterProvider) Query(org.graylog.plugins.views.search.Query) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) ESGeneratedQueryContext(org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext) DocumentContext(com.jayway.jsonpath.DocumentContext) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) QueryStringDecorator(org.graylog.plugins.views.search.engine.QueryStringDecorator) Test(org.junit.Test)

Example 24 with ESGeneratedQueryContext

use of org.graylog.storage.elasticsearch6.views.ESGeneratedQueryContext in project graylog2-server by Graylog2.

the class ESMessageListTest method usesHighlightingIfActivatedInConfig.

@Test
public void usesHighlightingIfActivatedInConfig() {
    MessageList messageList = someMessageList();
    ESGeneratedQueryContext context = generateQueryPartWithHighlighting(messageList);
    assertThat(context.searchSourceBuilder(messageList).highlighter()).isNotNull();
}
Also used : ESGeneratedQueryContext(org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 MessageList (org.graylog.plugins.views.search.searchtypes.MessageList)14 Query (org.graylog.plugins.views.search.Query)13 SearchJob (org.graylog.plugins.views.search.SearchJob)11 SearchType (org.graylog.plugins.views.search.SearchType)10 ESGeneratedQueryContext (org.graylog.storage.elasticsearch6.views.ESGeneratedQueryContext)9 ESGeneratedQueryContext (org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext)9 Map (java.util.Map)8 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)7 ESSearchTypeHandler (org.graylog.storage.elasticsearch6.views.searchtypes.ESSearchTypeHandler)7 DocumentContext (com.jayway.jsonpath.DocumentContext)6 SearchSourceBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder)6 Collections (java.util.Collections)5 List (java.util.List)5 Optional (java.util.Optional)5 Set (java.util.Set)5 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)5 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 Collectors (java.util.stream.Collectors)4