### Question:
QueryBuilders { static BoolQueryBuilder boolQuery() { return new BoolQueryBuilder(); } private  QueryBuilders();   }### Answer:
@Test public void boolQuery() throws Exception { QueryBuilders.QueryBuilder q1 = QueryBuilders.boolQuery().must( QueryBuilders.termQuery( "foo", "bar" ) ); assertEquals( "{\"bool\":{\"must\":{\"term\":{\"foo\":\"bar\"}}}}", toJson( q1 ) ); QueryBuilders.QueryBuilder q2 = QueryBuilders.boolQuery().must( QueryBuilders.termQuery( "f1", "v1" ) ).must( QueryBuilders.termQuery( "f2", "v2" ) ); assertEquals( "{\"bool\":{\"must\":[{\"term\":{\"f1\":\"v1\"}},{\"term\":{\"f2\":\"v2\"}}]}}", toJson( q2 ) ); QueryBuilders.QueryBuilder q3 = QueryBuilders.boolQuery().mustNot( QueryBuilders.termQuery( "f1", "v1" ) ); assertEquals( "{\"bool\":{\"must_not\":{\"term\":{\"f1\":\"v1\"}}}}", toJson( q3 ) ); }
@Test void boolQuery() throws Exception { QueryBuilders.QueryBuilder q1 = QueryBuilders.boolQuery() .must(QueryBuilders.termQuery("foo", "bar")); assertEquals("{\"bool\":{\"must\":{\"term\":{\"foo\":\"bar\"}}}}", toJson(q1)); QueryBuilders.QueryBuilder q2 = QueryBuilders.boolQuery() .must(QueryBuilders.termQuery("f1", "v1")).must(QueryBuilders.termQuery("f2", "v2")); assertEquals("{\"bool\":{\"must\":[{\"term\":{\"f1\":\"v1\"}},{\"term\":{\"f2\":\"v2\"}}]}}", toJson(q2)); QueryBuilders.QueryBuilder q3 = QueryBuilders.boolQuery() .mustNot(QueryBuilders.termQuery("f1", "v1")); assertEquals("{\"bool\":{\"must_not\":{\"term\":{\"f1\":\"v1\"}}}}", toJson(q3)); }