Java Code Examples for org.elasticsearch.index.query.BoolQueryBuilder#minimumShouldMatch()

The following examples show how to use org.elasticsearch.index.query.BoolQueryBuilder#minimumShouldMatch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BoolApiMain.java    From elasticsearch-pool with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
        RestHighLevelClient client = HighLevelClient.getInstance();
        try{
            BoolQueryBuilder matchQueryBuilder = QueryBuilders.boolQuery();
            matchQueryBuilder.must(QueryBuilders.termQuery("cpname","llbxinterface"));
            matchQueryBuilder.mustNot(QueryBuilders.termQuery("status","fail"));
            matchQueryBuilder.should(QueryBuilders.rangeQuery("utm").from(0,true).to(100,true));
            matchQueryBuilder.minimumShouldMatch(1);
//            matchQueryBuilder.filter();

            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(matchQueryBuilder);
            searchSourceBuilder.from(0);
            searchSourceBuilder.size(3);

            SearchRequest searchRequest = new SearchRequest("serverlog_20180701");//限定index
            searchRequest.types("log");//限定type
            searchRequest.source(searchSourceBuilder);

            SearchResponse searchResponse = client.search(searchRequest);
            System.out.println(searchResponse);


        }finally{
            HighLevelClient.close();
        }
    }
 
Example 2
Source File: ElasticsearchSearchVertexQuery.java    From vertexium with Apache License 2.0 5 votes vote down vote up
private QueryBuilder orFilters(List<QueryBuilder> filters) {
    if (filters.size() == 1) {
        return filters.get(0);
    } else {
        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
        for (QueryBuilder filter : filters) {
            boolQuery.should(filter);
        }
        boolQuery.minimumShouldMatch(1);
        return boolQuery;
    }
}
 
Example 3
Source File: ElasticsearchSearchVertexQuery.java    From vertexium with Apache License 2.0 5 votes vote down vote up
private QueryBuilder orFilters(List<QueryBuilder> filters) {
    if (filters.size() == 1) {
        return filters.get(0);
    } else {
        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
        for (QueryBuilder filter : filters) {
            boolQuery.should(filter);
        }
        boolQuery.minimumShouldMatch(1);
        return boolQuery;
    }
}
 
Example 4
Source File: SuggestBackendKV.java    From heroic with Apache License 2.0 5 votes vote down vote up
@Override
public QueryBuilder visitOr(final OrFilter or) {
    BoolQueryBuilder boolBuilder = new BoolQueryBuilder();

    for (final Filter stmt : or.terms()) {
        boolBuilder.should(filter(stmt));
    }

    boolBuilder.minimumShouldMatch(1);
    return boolBuilder;
}
 
Example 5
Source File: MetadataBackendKV.java    From heroic with Apache License 2.0 5 votes vote down vote up
@Override
public QueryBuilder visitOr(final OrFilter or) {
    BoolQueryBuilder boolQuery = new BoolQueryBuilder();
    for (QueryBuilder qb : convertTerms(or.terms())) {
        boolQuery.should(qb);
    }
    boolQuery.minimumShouldMatch(1);
    return boolQuery;
}
 
Example 6
Source File: YaCyQuery.java    From yacy_grid_mcp with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static QueryBuilder exactMatchQueryBuilder(String q, Boosts boosts) {
    BoolQueryBuilder qb = QueryBuilders.boolQuery();
    boosts.forEach((mapping, boost) -> qb.should(QueryBuilders.termQuery(mapping.getMapping().name(), q)));
    qb.minimumShouldMatch(1);
    return qb;
}