use of org.graylog.plugins.views.search.Query in project graylog2-server by Graylog2.
the class ElasticsearchBackend method checkForFailedShards.
private Optional<ElasticsearchException> checkForFailedShards(MultiSearchResponse.Item multiSearchResponse) {
if (multiSearchResponse.isFailure()) {
return Optional.of(new ElasticsearchException(multiSearchResponse.getFailureMessage(), multiSearchResponse.getFailure()));
}
final SearchResponse searchResponse = multiSearchResponse.getResponse();
if (searchResponse != null && searchResponse.getFailedShards() > 0) {
final List<Throwable> shardFailures = Arrays.stream(searchResponse.getShardFailures()).map(ShardOperationFailedException::getCause).collect(Collectors.toList());
final List<String> nonNumericFieldErrors = shardFailures.stream().filter(shardFailure -> shardFailure.getMessage().contains("Expected numeric type on field")).map(Throwable::getMessage).distinct().collect(Collectors.toList());
if (!nonNumericFieldErrors.isEmpty()) {
return Optional.of(new FieldTypeException("Unable to perform search query: ", nonNumericFieldErrors));
}
final List<String> errors = shardFailures.stream().map(Throwable::getMessage).distinct().collect(Collectors.toList());
return Optional.of(new ElasticsearchException("Unable to perform search query: ", errors));
}
return Optional.empty();
}
use of org.graylog.plugins.views.search.Query in project graylog2-server by Graylog2.
the class QueryBackend method effectiveTimeRangeForResult.
default AbsoluteRange effectiveTimeRangeForResult(Query query, QueryResult queryResult) {
final TimeRange effectiveTimeRange = query.globalOverride().flatMap(GlobalOverride::timerange).orElse(query.timerange());
if (isAllMessages(effectiveTimeRange)) {
final Optional<AbsoluteRange> effectiveRange = queryResult.searchTypes().values().stream().filter(result -> result instanceof PivotResult).map(result -> ((PivotResult) result).effectiveTimerange()).reduce((prev, next) -> {
final DateTime from = prev.from().compareTo(next.from()) < 0 ? prev.from() : next.from();
final DateTime to = prev.to().compareTo(next.to()) < 0 ? next.to() : prev.to();
return AbsoluteRange.create(from, to);
});
if (effectiveRange.isPresent()) {
return effectiveRange.get();
}
}
return AbsoluteRange.create(effectiveTimeRange.getFrom(), effectiveTimeRange.getTo());
}
use of org.graylog.plugins.views.search.Query in project graylog2-server by Graylog2.
the class SearchResourceTest method mockNewSearch.
private Search mockNewSearch() {
final Search search = mock(Search.class);
when(search.addStreamsToQueriesWithoutStreams(any())).thenReturn(search);
final String streamId = "streamId";
final Query query = mock(Query.class);
when(query.id()).thenReturn("queryId");
when(query.usedStreamIds()).thenReturn(ImmutableSet.of(streamId));
when(query.searchTypes()).thenReturn(ImmutableSet.of());
when(search.queries()).thenReturn(ImmutableSet.of(query));
return search;
}
use of org.graylog.plugins.views.search.Query in project graylog2-server by Graylog2.
the class CommandFactoryTest method takesStreamsFromQueryIfEmptyOnSearchType.
@Test
void takesStreamsFromQueryIfEmptyOnSearchType() {
MessageList ml = MessageList.builder().id("ml-id").build();
Query q = validQueryBuilderWith(ml).filter(streamFilter("stream-3")).build();
Search s = searchWithQueries(q);
ExportMessagesCommand command = buildFrom(s, ml.id());
assertThat(command.streams()).isEqualTo(q.usedStreamIds());
}
use of org.graylog.plugins.views.search.Query in project graylog2-server by Graylog2.
the class CommandFactoryTest method takesDefaultFieldsIfNotSpecifiedInResultFormat.
@Test
void takesDefaultFieldsIfNotSpecifiedInResultFormat() {
MessageList ml = MessageList.builder().id("ml-id").build();
Query q = validQueryBuilderWith(ml).build();
Search s = searchWithQueries(q);
ExportMessagesCommand command = buildFrom(s, ml.id(), ResultFormat.builder().build());
assertThat(command.fieldsInOrder()).isEqualTo(DEFAULT_FIELDS);
}
Aggregations