use of org.graylog.plugins.views.search.filter.StreamFilter in project graylog2-server by Graylog2.
the class SearchExecutionGuardTest method searchWithStreamIds.
private Search searchWithStreamIds(RelativeRange timeRange, String... streamIds) {
final StreamFilter[] filters = Arrays.stream(streamIds).map(StreamFilter::ofId).toArray(StreamFilter[]::new);
final Query query = Query.builder().id("").timerange(timeRange).searchTypes(ImmutableSet.of(EventList.builder().id("event-list").streams(ImmutableSet.copyOf(streamIds)).build())).query(ElasticsearchQueryString.empty()).filter(OrFilter.or(filters)).build();
return Search.Builder.create().id("searchId").queries(ImmutableSet.of(query)).build();
}
use of org.graylog.plugins.views.search.filter.StreamFilter in project graylog2-server by Graylog2.
the class ElasticsearchBackend method generateFilterClause.
// TODO make pluggable
public Optional<QueryBuilder> generateFilterClause(Filter filter, SearchJob job, Query query) {
if (filter == null) {
return Optional.empty();
}
switch(filter.type()) {
case AndFilter.NAME:
final BoolQueryBuilder andBuilder = QueryBuilders.boolQuery();
filter.filters().stream().map(filter1 -> generateFilterClause(filter1, job, query)).forEach(optQueryBuilder -> optQueryBuilder.ifPresent(andBuilder::must));
return Optional.of(andBuilder);
case OrFilter.NAME:
final BoolQueryBuilder orBuilder = QueryBuilders.boolQuery();
// TODO for the common case "any of these streams" we can optimize the filter into
// a single "termsQuery" instead of "termQuery OR termQuery" if all direct children are "StreamFilter"
filter.filters().stream().map(filter1 -> generateFilterClause(filter1, job, query)).forEach(optQueryBuilder -> optQueryBuilder.ifPresent(orBuilder::should));
return Optional.of(orBuilder);
case StreamFilter.NAME:
// Skipping stream filter, will be extracted elsewhere
return Optional.empty();
case QueryStringFilter.NAME:
return Optional.of(QueryBuilders.queryStringQuery(this.queryStringDecorators.decorate(((QueryStringFilter) filter).query(), job, query)));
}
return Optional.empty();
}
Aggregations