Search in sources :

Example 1 with QueryBuilders

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

Aggregations

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