Search in sources :

Example 11 with SearchConfig

use of org.graylog.plugins.views.search.engine.SearchConfig in project graylog2-server by Graylog2.

the class ElasticsearchBackendMultiSearchTest method everySearchTypeGeneratesASearchSourceBuilder.

@Test
public void everySearchTypeGeneratesASearchSourceBuilder() {
    final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
    assertThat(queryContext.searchTypeQueries()).hasSize(2).containsOnlyKeys("pivot1", "pivot2");
}
Also used : SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test)

Example 12 with SearchConfig

use of org.graylog.plugins.views.search.engine.SearchConfig in project graylog2-server by Graylog2.

the class ElasticsearchBackendMultiSearchTest method everySearchTypeGeneratesOneESQuery.

@Test
public void everySearchTypeGeneratesOneESQuery() throws Exception {
    final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
    when(jestClient.execute(any(), any())).thenReturn(resultFor(resourceFile("successfulMultiSearchResponse.json")));
    final String generatedRequest = run(searchJob, query, queryContext, Collections.emptySet());
    assertThat(generatedRequest).isEqualTo(resourceFile("everySearchTypeGeneratesOneESQuery.request.ndjson"));
}
Also used : SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) Test(org.junit.Test)

Example 13 with SearchConfig

use of org.graylog.plugins.views.search.engine.SearchConfig in project graylog2-server by Graylog2.

the class ElasticsearchBackendMultiSearchTest method multiSearchResultsAreAssignedToSearchTypes.

@Test
public void multiSearchResultsAreAssignedToSearchTypes() throws Exception {
    final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
    when(jestClient.execute(any(), any())).thenReturn(resultFor(resourceFile("successfulMultiSearchResponse.json")));
    final QueryResult queryResult = this.elasticsearchBackend.doRun(searchJob, query, queryContext);
    assertThat(queryResult.searchTypes()).containsOnlyKeys("pivot1", "pivot2");
    final PivotResult pivot1Result = (PivotResult) queryResult.searchTypes().get("pivot1");
    assertThat(pivot1Result.rows().get(0)).isEqualTo(PivotResult.Row.builder().key(ImmutableList.of()).source("leaf").addValue(PivotResult.Value.create(Collections.singletonList("avg(field1)"), 27220.273504273504, true, "row-leaf")).build());
    final PivotResult pivot2Result = (PivotResult) queryResult.searchTypes().get("pivot2");
    assertThat(pivot2Result.rows().get(0)).isEqualTo(PivotResult.Row.builder().key(ImmutableList.of()).source("leaf").addValue(PivotResult.Value.create(Collections.singletonList("max(field2)"), 42.0, true, "row-leaf")).build());
}
Also used : QueryResult(org.graylog.plugins.views.search.QueryResult) PivotResult(org.graylog.plugins.views.search.searchtypes.pivot.PivotResult) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test)

Example 14 with SearchConfig

use of org.graylog.plugins.views.search.engine.SearchConfig in project graylog2-server by Graylog2.

the class ElasticsearchBackendQueryStringDecoratorsTest method generateJsonRequest.

private DocumentContext generateJsonRequest(Query query, SearchJob searchJob) {
    final ESGeneratedQueryContext context = this.backend.generate(searchJob, query, new SearchConfig(Period.ZERO));
    final String request = context.searchTypeQueries().get("testSearchtype").toString();
    return JsonPath.parse(request);
}
Also used : SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)

Example 15 with SearchConfig

use of org.graylog.plugins.views.search.engine.SearchConfig in project graylog2-server by Graylog2.

the class ElasticsearchBackendSearchTypesWithStreamsOverridesTest method run.

private MultiSearch run(Query query) throws IOException {
    final SearchJob job = searchJobForQuery(query);
    final ESGeneratedQueryContext context = this.elasticsearchBackend.generate(job, query, new SearchConfig(Period.ZERO));
    this.elasticsearchBackend.doRun(job, query, context);
    verify(jestClient, times(1)).execute(clientRequestCaptor.capture(), any());
    return clientRequestCaptor.getValue();
}
Also used : SearchJob(org.graylog.plugins.views.search.SearchJob) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig)

Aggregations

SearchConfig (org.graylog.plugins.views.search.engine.SearchConfig)26 Test (org.junit.Test)22 SearchJob (org.graylog.plugins.views.search.SearchJob)8 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)7 Query (org.graylog.plugins.views.search.Query)6 Search (org.graylog.plugins.views.search.Search)6 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)6 MultiSearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse)5 QueryResult (org.graylog.plugins.views.search.QueryResult)4 PivotResult (org.graylog.plugins.views.search.searchtypes.pivot.PivotResult)4 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)4 MultiSearch (io.searchbox.core.MultiSearch)3 ArrayList (java.util.ArrayList)2 SearchTypeError (org.graylog.plugins.views.search.errors.SearchTypeError)2 DerivedTimeRange (org.graylog.plugins.views.search.timeranges.DerivedTimeRange)2 DocumentContext (com.jayway.jsonpath.DocumentContext)1