use of org.graylog.storage.elasticsearch7.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;
}
use of org.graylog.storage.elasticsearch7.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!");
}
use of org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext 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");
}
use of org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext in project graylog2-server by Graylog2.
the class ElasticsearchBackendGeneratedRequestTestBase method setUpSUT.
@Before
public void setUpSUT() {
this.elasticSearchTypeHandlers = new HashMap<>();
final Map<String, ESPivotBucketSpecHandler<? extends BucketSpec, ? extends Aggregation>> bucketHandlers = Collections.emptyMap();
final Map<String, ESPivotSeriesSpecHandler<? extends SeriesSpec, ? extends Aggregation>> seriesHandlers = new HashMap<>();
seriesHandlers.put(Average.NAME, new ESAverageHandler());
seriesHandlers.put(Max.NAME, new ESMaxHandler());
elasticSearchTypeHandlers.put(Pivot.NAME, () -> new ESPivot(bucketHandlers, seriesHandlers));
this.elasticsearchBackend = new ElasticsearchBackend(elasticSearchTypeHandlers, client, indexLookup, new QueryStringDecorators.Fake(), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false);
}
use of org.graylog.storage.elasticsearch7.views.ESGeneratedQueryContext in project graylog2-server by Graylog2.
the class ElasticsearchBackendUsingCorrectIndicesTest method setupSUT.
@Before
public void setupSUT() throws Exception {
final MultiSearchResponse response = TestMultisearchResponse.fromFixture("successfulResponseWithSingleQuery.json");
final List<MultiSearchResponse.Item> items = Arrays.stream(response.getResponses()).collect(Collectors.toList());
when(client.msearch(any(), any())).thenReturn(items);
final FieldTypesLookup fieldTypesLookup = mock(FieldTypesLookup.class);
this.backend = new ElasticsearchBackend(handlers, client, indexLookup, new QueryStringDecorators.Fake(), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false);
}
Aggregations