Java boolean query

I'm working with a Java query like this

List queries = new ArrayList<>();
I want to pass all the queries to build a query with several must clauses. Is it possible to pass the queries like this
queryBuilder = QueryBuilders.boolQuery().must(queries);

The BoolQueryBuilder#must() method only accepts a single query, but you can chain them together, wither manually like boolQueryBuilder.must(query1).must(query2)... or add all your queries in a loop.

1 Like


Yes, I've seen how to do it:

BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
                .forEach(p -> queryBuilder.must(QueryBuilders.termQuery(p.getKey(), p.getValue())));