use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilders in project graylog2-server by Graylog2.
the class SearchRequestFactory method create.
public SearchSourceBuilder create(SearchCommand searchCommand) {
final String query = normalizeQuery(searchCommand.query());
final QueryBuilder queryBuilder = isWildcardQuery(query) ? matchAllQuery() : queryStringQuery(query).allowLeadingWildcard(allowLeadingWildcardSearches);
final Optional<BoolQueryBuilder> rangeQueryBuilder = searchCommand.range().map(TimeRangeQueryFactory::create).map(rangeQuery -> boolQuery().must(rangeQuery));
final Optional<BoolQueryBuilder> filterQueryBuilder = searchCommand.filter().filter(filter -> !isWildcardQuery(filter)).map(QueryBuilders::queryStringQuery).map(queryStringQuery -> boolQuery().must(queryStringQuery));
final BoolQueryBuilder filteredQueryBuilder = boolQuery().must(queryBuilder);
filterQueryBuilder.ifPresent(filteredQueryBuilder::filter);
rangeQueryBuilder.ifPresent(filteredQueryBuilder::filter);
applyStreamsFilter(filteredQueryBuilder, searchCommand);
final SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(filteredQueryBuilder).trackTotalHits(true);
applyPaginationIfPresent(searchSourceBuilder, searchCommand);
applySortingIfPresent(searchSourceBuilder, searchCommand);
applyHighlighting(searchSourceBuilder);
return searchSourceBuilder;
}
Aggregations