Search in sources :

Example 21 with BoolQueryBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project gerrit by GerritCodeReview.

the class ElasticQueryBuilder method not.

private <T> QueryBuilder not(Predicate<T> p) throws QueryParseException {
    Predicate<T> n = p.getChild(0);
    if (n instanceof TimestampRangePredicate) {
        return notTimestamp((TimestampRangePredicate<T>) n);
    }
    // Lucene does not support negation, start with all and subtract.
    BoolQueryBuilder q = QueryBuilders.boolQuery();
    q.must(QueryBuilders.matchAllQuery());
    q.mustNot(toQueryBuilder(n));
    return q;
}
Also used : TimestampRangePredicate(com.google.gerrit.server.index.TimestampRangePredicate) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 22 with BoolQueryBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.

the class SearchService method getDocumentListByDocIds.

public List<Map<String, Object>> getDocumentListByDocIds(final String[] docIds, final String[] fields, final OptionalThing<FessUserBean> userBean, final SearchRequestType searchRequestType) {
    return fessEsClient.getDocumentList(fessConfig.getIndexDocumentSearchIndex(), fessConfig.getIndexDocumentType(), builder -> {
        final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().must(QueryBuilders.termsQuery(fessConfig.getIndexFieldDocId(), docIds));
        if (searchRequestType != SearchRequestType.ADMIN_SEARCH) {
            final Set<String> roleSet = ComponentUtil.getRoleQueryHelper().build(searchRequestType);
            if (!roleSet.isEmpty()) {
                final BoolQueryBuilder roleQuery = QueryBuilders.boolQuery();
                roleSet.stream().forEach(name -> {
                    roleQuery.should(QueryBuilders.termQuery(fessConfig.getIndexFieldRole(), name));
                });
                boolQuery.filter(roleQuery);
            }
        }
        builder.setQuery(boolQuery);
        builder.setSize(fessConfig.getPagingSearchPageMaxSizeAsInteger().intValue());
        builder.setFetchSource(fields, null);
        fessConfig.processSearchPreference(builder, userBean);
        return true;
    });
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 23 with BoolQueryBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.

the class SearchService method getDocumentByDocId.

public OptionalEntity<Map<String, Object>> getDocumentByDocId(final String docId, final String[] fields, final OptionalThing<FessUserBean> userBean) {
    return fessEsClient.getDocument(fessConfig.getIndexDocumentSearchIndex(), fessConfig.getIndexDocumentType(), builder -> {
        final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().must(QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), docId));
        final Set<String> roleSet = ComponentUtil.getRoleQueryHelper().build(SearchRequestType.JSON);
        if (!roleSet.isEmpty()) {
            final BoolQueryBuilder roleQuery = QueryBuilders.boolQuery();
            roleSet.stream().forEach(name -> {
                roleQuery.should(QueryBuilders.termQuery(fessConfig.getIndexFieldRole(), name));
            });
            boolQuery.filter(roleQuery);
        }
        builder.setQuery(boolQuery);
        builder.setFetchSource(fields, null);
        fessConfig.processSearchPreference(builder, userBean);
        return true;
    });
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 24 with BoolQueryBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.

the class BsLabelToRoleCQ method bool.

public void bool(BoolCall<LabelToRoleCQ> boolLambda, ConditionOptionCall<BoolQueryBuilder> opLambda) {
    LabelToRoleCQ mustQuery = new LabelToRoleCQ();
    LabelToRoleCQ shouldQuery = new LabelToRoleCQ();
    LabelToRoleCQ mustNotQuery = new LabelToRoleCQ();
    LabelToRoleCQ filterQuery = new LabelToRoleCQ();
    boolLambda.callback(mustQuery, shouldQuery, mustNotQuery, filterQuery);
    if (mustQuery.hasQueries() || shouldQuery.hasQueries() || mustNotQuery.hasQueries() || filterQuery.hasQueries()) {
        BoolQueryBuilder builder = regBoolCQ(mustQuery.getQueryBuilderList(), shouldQuery.getQueryBuilderList(), mustNotQuery.getQueryBuilderList(), filterQuery.getQueryBuilderList());
        if (opLambda != null) {
            opLambda.callback(builder);
        }
    }
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) LabelToRoleCQ(org.codelibs.fess.es.config.cbean.cq.LabelToRoleCQ)

Example 25 with BoolQueryBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.

the class BsFileConfigToRoleCQ method bool.

public void bool(BoolCall<FileConfigToRoleCQ> boolLambda, ConditionOptionCall<BoolQueryBuilder> opLambda) {
    FileConfigToRoleCQ mustQuery = new FileConfigToRoleCQ();
    FileConfigToRoleCQ shouldQuery = new FileConfigToRoleCQ();
    FileConfigToRoleCQ mustNotQuery = new FileConfigToRoleCQ();
    FileConfigToRoleCQ filterQuery = new FileConfigToRoleCQ();
    boolLambda.callback(mustQuery, shouldQuery, mustNotQuery, filterQuery);
    if (mustQuery.hasQueries() || shouldQuery.hasQueries() || mustNotQuery.hasQueries() || filterQuery.hasQueries()) {
        BoolQueryBuilder builder = regBoolCQ(mustQuery.getQueryBuilderList(), shouldQuery.getQueryBuilderList(), mustNotQuery.getQueryBuilderList(), filterQuery.getQueryBuilderList());
        if (opLambda != null) {
            opLambda.callback(builder);
        }
    }
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FileConfigToRoleCQ(org.codelibs.fess.es.config.cbean.cq.FileConfigToRoleCQ)

Aggregations

BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)201 SearchResponse (org.elasticsearch.action.search.SearchResponse)73 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)58 SearchHit (org.elasticsearch.search.SearchHit)41 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)38 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)30 Map (java.util.Map)29 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)25 List (java.util.List)23 SearchRequest (org.elasticsearch.action.search.SearchRequest)21 Test (org.junit.Test)18 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)16 TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)16 QueryBuilders (org.elasticsearch.index.query.QueryBuilders)14 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)13 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 LinkedList (java.util.LinkedList)11 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)11