use of org.graylog.plugins.views.search.searchtypes.pivot.PivotResult in project graylog2-server by Graylog2.
the class ESPivotTest method searchResultForAllMessagesIncludesTimerangeOfDocuments.
@Test
public void searchResultForAllMessagesIncludesTimerangeOfDocuments() throws InvalidRangeParametersException {
DateTimeUtils.setCurrentMillisFixed(1578584665408L);
final long documentCount = 424242;
returnDocumentCount(queryResult, documentCount);
final Aggregations mockMetricAggregation = createTimestampRangeAggregations((double) new Date(1547303022000L).getTime(), (double) new Date(1578040943000L).getTime());
when(queryResult.getAggregations()).thenReturn(mockMetricAggregation);
when(query.effectiveTimeRange(pivot)).thenReturn(RelativeRange.create(0));
final SearchType.Result result = this.esPivot.doExtractResult(job, query, pivot, queryResult, aggregations, queryContext);
final PivotResult pivotResult = (PivotResult) result;
assertThat(pivotResult.effectiveTimerange()).isEqualTo(AbsoluteRange.create(DateTime.parse("2019-01-12T14:23:42.000Z"), DateTime.parse("2020-01-03T08:42:23.000Z")));
DateTimeUtils.setCurrentMillisSystem();
}
use of org.graylog.plugins.views.search.searchtypes.pivot.PivotResult in project graylog2-server by Graylog2.
the class ElasticsearchBackendMultiSearchTest method oneFailingSearchTypeReturnsPartialResults.
@Test
public void oneFailingSearchTypeReturnsPartialResults() throws Exception {
final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
final MultiSearchResponse response = TestMultisearchResponse.fromFixture("partiallySuccessfulMultiSearchResponse.json");
final List<MultiSearchResponse.Item> items = Arrays.stream(response.getResponses()).collect(Collectors.toList());
when(client.msearch(any(), any())).thenReturn(items);
final QueryResult queryResult = this.elasticsearchBackend.doRun(searchJob, query, queryContext);
assertThat(queryResult.errors()).hasSize(1);
final SearchTypeError searchTypeError = (SearchTypeError) new ArrayList<>(queryResult.errors()).get(0);
assertThat(searchTypeError.description()).isEqualTo("Unable to perform search query: \n" + "\n" + "Elasticsearch exception [type=illegal_argument_exception, reason=Expected numeric type on field [field1], but got [keyword]].");
assertThat(searchTypeError.searchTypeId()).isEqualTo("pivot1");
assertThat(queryResult.searchTypes()).containsOnlyKeys("pivot2");
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());
}
use of org.graylog.plugins.views.search.searchtypes.pivot.PivotResult in project graylog2-server by Graylog2.
the class PivotAggregationSearch method doSearch.
@Override
public AggregationResult doSearch() throws EventProcessorException {
final SearchJob searchJob = getSearchJob(parameters, searchOwner, config.searchWithinMs(), config.executeEveryMs());
final QueryResult queryResult = searchJob.results().get(QUERY_ID);
final QueryResult streamQueryResult = searchJob.results().get(STREAMS_QUERY_ID);
final Set<SearchError> aggregationErrors = firstNonNull(queryResult.errors(), Collections.emptySet());
final Set<SearchError> streamErrors = firstNonNull(streamQueryResult.errors(), Collections.emptySet());
if (!aggregationErrors.isEmpty() || !streamErrors.isEmpty()) {
final Set<SearchError> errors = aggregationErrors.isEmpty() ? streamErrors : aggregationErrors;
errors.forEach(error -> {
if (error instanceof QueryError) {
final QueryError queryError = (QueryError) error;
final String backtrace = queryError.backtrace() != null ? queryError.backtrace() : "";
if (error instanceof EmptyParameterError) {
LOG.debug("Aggregation search query <{}> with empty Parameter: {}\n{}", queryError.queryId(), queryError.description(), backtrace);
} else {
LOG.error("Aggregation search query <{}> returned an error: {}\n{}", queryError.queryId(), queryError.description(), backtrace);
}
} else {
LOG.error("Aggregation search returned an error: {}", error);
}
});
// If we have only EmptyParameterErrors, just return an empty Result
if (!(errors.stream().filter(e -> !(e instanceof EmptyParameterError)).count() > 1)) {
return AggregationResult.empty();
}
if (errors.size() > 1) {
throw new EventProcessorException("Pivot search failed with multiple errors.", false, eventDefinition);
} else {
throw new EventProcessorException(errors.iterator().next().description(), false, eventDefinition);
}
}
final PivotResult pivotResult = (PivotResult) queryResult.searchTypes().get(PIVOT_ID);
final PivotResult streamsResult = (PivotResult) streamQueryResult.searchTypes().get(STREAMS_PIVOT_ID);
return AggregationResult.builder().keyResults(extractValues(pivotResult)).effectiveTimerange(pivotResult.effectiveTimerange()).totalAggregatedMessages(pivotResult.total()).sourceStreams(extractSourceStreams(streamsResult)).build();
}
Aggregations