Search in sources :

Example 1 with QueryBuilders

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;
}
Also used : BoolQueryBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.BoolQueryBuilder) QueryBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.BoolQueryBuilder) SearchSourceBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder)

Aggregations

BoolQueryBuilder (org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.BoolQueryBuilder)1 QueryBuilder (org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder)1 SearchSourceBuilder (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder)1