Search in sources :

Example 26 with BoolQueryBuilder

use of 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 27 with BoolQueryBuilder

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

the class EsAbstractConditionQuery method regBoolCQ.

protected BoolQueryBuilder regBoolCQ(List<QueryBuilder> mustList, List<QueryBuilder> shouldList, List<QueryBuilder> mustNotList, List<QueryBuilder> filterList) {
    assertObjectNotNull("mustList", mustList);
    assertObjectNotNull("shouldList", shouldList);
    assertObjectNotNull("mustNotList", mustNotList);
    assertObjectNotNull("filterList", filterList);
    BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
    mustList.forEach(query -> {
        boolQuery.must(query);
    });
    shouldList.forEach(query -> {
        boolQuery.should(query);
    });
    mustNotList.forEach(query -> {
        boolQuery.mustNot(query);
    });
    filterList.forEach(query -> {
        boolQuery.filter(query);
    });
    regQ(boolQuery);
    return boolQuery;
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 28 with BoolQueryBuilder

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

the class EsAbstractConditionQuery method getQuery.

public QueryBuilder getQuery() {
    if (queryBuilderList == null) {
        return null;
    } else if (queryBuilderList.size() == 1) {
        return queryBuilderList.get(0);
    }
    BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
    queryBuilderList.forEach(query -> {
        boolQuery.must(query);
    });
    return boolQuery;
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 29 with BoolQueryBuilder

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

the class BsAccessTokenCQ method bool.

public void bool(BoolCall<AccessTokenCQ> boolLambda, ConditionOptionCall<BoolQueryBuilder> opLambda) {
    AccessTokenCQ mustQuery = new AccessTokenCQ();
    AccessTokenCQ shouldQuery = new AccessTokenCQ();
    AccessTokenCQ mustNotQuery = new AccessTokenCQ();
    AccessTokenCQ filterQuery = new AccessTokenCQ();
    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 : AccessTokenCQ(org.codelibs.fess.es.config.cbean.cq.AccessTokenCQ) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Example 30 with BoolQueryBuilder

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

the class BsBoostDocumentRuleCQ method bool.

public void bool(BoolCall<BoostDocumentRuleCQ> boolLambda, ConditionOptionCall<BoolQueryBuilder> opLambda) {
    BoostDocumentRuleCQ mustQuery = new BoostDocumentRuleCQ();
    BoostDocumentRuleCQ shouldQuery = new BoostDocumentRuleCQ();
    BoostDocumentRuleCQ mustNotQuery = new BoostDocumentRuleCQ();
    BoostDocumentRuleCQ filterQuery = new BoostDocumentRuleCQ();
    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) BoostDocumentRuleCQ(org.codelibs.fess.es.config.cbean.cq.BoostDocumentRuleCQ)

Aggregations

BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)98 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)25 SearchResponse (org.elasticsearch.action.search.SearchResponse)15 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)9 MatchQueryBuilder (org.elasticsearch.index.query.MatchQueryBuilder)9 HasParentQueryBuilder (org.elasticsearch.index.query.HasParentQueryBuilder)8 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 MatchAllQueryBuilder (org.elasticsearch.index.query.MatchAllQueryBuilder)5 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)5 Map (java.util.Map)4 AbstractAggregationBuilder (org.elasticsearch.search.aggregations.AbstractAggregationBuilder)4 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)4 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 StickyFacetBuilder (org.sonar.server.es.StickyFacetBuilder)4 HasChildQueryBuilder (org.elasticsearch.index.query.HasChildQueryBuilder)3 InnerHitBuilder (org.elasticsearch.index.query.InnerHitBuilder)3