Search in sources :

Example 1 with MessageList

use of org.graylog.plugins.views.search.searchtypes.MessageList in project graylog2-server by Graylog2.

the class SearchDriver method allMessagesJson.

private static String allMessagesJson(String queryId, String messageListId, TimeRange timeRange) {
    MessageList messageList = MessageList.builder().id(messageListId).build();
    QueryDTO q = QueryDTO.builder().id(queryId).query(ElasticsearchQueryString.of("")).timerange(timeRange).searchTypes(ImmutableSet.of(messageList)).build();
    SearchDTO s = SearchDTO.builder().id(new ObjectId().toHexString()).queries(ImmutableSet.of(q)).build();
    return JsonUtils.toJsonString(s);
}
Also used : ObjectId(org.bson.types.ObjectId) QueryDTO(org.graylog.plugins.views.search.rest.QueryDTO) SearchDTO(org.graylog.plugins.views.search.rest.SearchDTO) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList)

Example 2 with MessageList

use of org.graylog.plugins.views.search.searchtypes.MessageList in project graylog2-server by Graylog2.

the class ESMessageListTest method doesNotUseHighlightingIfDeactivatedInConfig.

@Test
public void doesNotUseHighlightingIfDeactivatedInConfig() {
    MessageList messageList = someMessageList();
    ESGeneratedQueryContext context = generateQueryPartWithoutHighlighting(messageList);
    assertThat(context.searchSourceBuilder(messageList).highlighter()).as("there should be no highlighter configured").isNull();
}
Also used : ESGeneratedQueryContext(org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) Test(org.junit.Test)

Example 3 with MessageList

use of org.graylog.plugins.views.search.searchtypes.MessageList in project graylog2-server by Graylog2.

the class ESMessageListTest method passesNullForUnmappedTypeIfTypeIsNotFound.

@Test
public void passesNullForUnmappedTypeIfTypeIsNotFound() {
    final MessageList messageList = someMessageListWithSorting("stream1", "somefield");
    final ESGeneratedQueryContext context = mockQueryContext(messageList);
    when(context.fieldType(Collections.singleton("stream1"), "somefield")).thenReturn(Optional.empty());
    final ESGeneratedQueryContext queryContext = generateQueryPartWithContextFor(messageList, true, Collections.emptySet(), context);
    final DocumentContext doc = JsonPath.parse(queryContext.searchSourceBuilder(messageList).toString());
    assertThat(doc.read("$.sort[0].somefield", Map.class)).doesNotContainKey("unmapped_type");
}
Also used : ESGeneratedQueryContext(org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext) DocumentContext(com.jayway.jsonpath.DocumentContext) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) Test(org.junit.Test)

Example 4 with MessageList

use of org.graylog.plugins.views.search.searchtypes.MessageList 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 5 with MessageList

use of org.graylog.plugins.views.search.searchtypes.MessageList in project graylog2-server by Graylog2.

the class ESMessageListTest method passesTypeOfSortingFieldAsUnmappedType.

@Test
public void passesTypeOfSortingFieldAsUnmappedType() {
    final MessageList messageList = someMessageListWithSorting("stream1", "somefield");
    final ESGeneratedQueryContext context = mockQueryContext(messageList);
    when(context.fieldType(Collections.singleton("stream1"), "somefield")).thenReturn(Optional.of("long"));
    final ESGeneratedQueryContext queryContext = generateQueryPartWithContextFor(messageList, true, Collections.emptySet(), context);
    final DocumentContext doc = JsonPath.parse(queryContext.searchSourceBuilder(messageList).toString());
    JsonPathAssert.assertThat(doc).jsonPathAsString("$.sort[0].somefield.unmapped_type").isEqualTo("long");
}
Also used : ESGeneratedQueryContext(org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext) DocumentContext(com.jayway.jsonpath.DocumentContext) MessageList(org.graylog.plugins.views.search.searchtypes.MessageList) Test(org.junit.Test)

Aggregations

MessageList (org.graylog.plugins.views.search.searchtypes.MessageList)27 Query (org.graylog.plugins.views.search.Query)15 Test (org.junit.Test)13 Search (org.graylog.plugins.views.search.Search)10 Test (org.junit.jupiter.api.Test)10 DocumentContext (com.jayway.jsonpath.DocumentContext)6 ESGeneratedQueryContext (org.graylog.storage.elasticsearch6.views.ESGeneratedQueryContext)6 ESGeneratedQueryContext (org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext)6 SearchType (org.graylog.plugins.views.search.SearchType)5 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)4 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)4 Optional (java.util.Optional)3 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)2 Named (com.google.inject.name.Named)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2