use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilders in project graylog2-server by Graylog2.
the class SearchesAdapterES6 method buildSearchRequest.
private SearchSourceBuilder buildSearchRequest(ScrollCommand scrollCommand) {
final String query = normalizeQuery(scrollCommand.query());
final QueryBuilder queryBuilder = isWildcardQuery(query) ? matchAllQuery() : queryStringQuery(query).allowLeadingWildcard(configuration.isAllowLeadingWildcardSearches());
final Optional<BoolQueryBuilder> rangeQueryBuilder = scrollCommand.range().map(range -> QueryBuilders.boolQuery().must(TimeRangeQueryFactory.create(range)));
final Optional<BoolQueryBuilder> filterQueryBuilder = scrollCommand.filter().filter(filter -> !isWildcardQuery(filter)).map(QueryBuilders::queryStringQuery).map(filter -> rangeQueryBuilder.orElse(QueryBuilders.boolQuery()).must(filter));
final BoolQueryBuilder filteredQueryBuilder = QueryBuilders.boolQuery().must(queryBuilder);
filterQueryBuilder.ifPresent(filteredQueryBuilder::filter);
applyStreamsFilter(filteredQueryBuilder, scrollCommand);
final SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(filteredQueryBuilder);
applyPaginationIfPresent(searchSourceBuilder, scrollCommand);
applySortingIfPresent(searchSourceBuilder, scrollCommand);
applyHighlighting(searchSourceBuilder, scrollCommand);
return searchSourceBuilder;
}
Aggregations