public static BoolQueryBuilder boolQuery() {
        return new BoolQueryBuilder();
    }
@Test
    public void testBoolQuery() throws Exception {
        QueryBuilders.QueryBuilder q1 = QueryBuilders.boolQuery()
                .must(QueryBuilders.termQuery("k", "aaa"));

        assertEquals("{\"bool\":{\"must\":{\"term\":{\"k\":\"aaa\"}}}}",
                toJson(q1));

        QueryBuilders.QueryBuilder q2 = QueryBuilders.boolQuery()
                .must(QueryBuilders.termQuery("k1", "aaa")).must(QueryBuilders.termQuery("k2", "bbb"));

        assertEquals("{\"bool\":{\"must\":[{\"term\":{\"k1\":\"aaa\"}},{\"term\":{\"k2\":\"bbb\"}}]}}",
                toJson(q2));

        QueryBuilders.QueryBuilder q3 = QueryBuilders.boolQuery()
                .mustNot(QueryBuilders.termQuery("k", "fff"));

        assertEquals("{\"bool\":{\"must_not\":{\"term\":{\"k\":\"fff\"}}}}",
                toJson(q3));

        QueryBuilders.QueryBuilder q4 = QueryBuilders.rangeQuery("k1").lt(200).gt(-200);
        QueryBuilders.QueryBuilder q5 = QueryBuilders.termsQuery("k2", Arrays.asList("aaa", "bbb", "ccc"));
        QueryBuilders.QueryBuilder q6 = QueryBuilders.boolQuery().must(q4).should(q5);
        assertEquals(
                "{\"bool\":{\"must\":{\"range\":{\"k1\":{\"gt\":-200,\"lt\":200}}}," +
                        "\"should\":{\"terms\":{\"k2\":[\"aaa\",\"bbb\",\"ccc\"]}}}}",
                toJson(q6));
        assertEquals(
                "{\"bool\":{\"filter\":[{\"range\":{\"k1\":{\"gt\":-200,\"lt\":200}}}," +
                        "{\"terms\":{\"k2\":[\"aaa\",\"bbb\",\"ccc\"]}}]}}",
                toJson(QueryBuilders.boolQuery().filter(q4).filter(q5)));
        assertEquals(
                "{\"bool\":{\"filter\":{\"range\":{\"k1\":{\"gt\":-200,\"lt\":200}}}," +
                        "\"must_not\":{\"terms\":{\"k2\":[\"aaa\",\"bbb\",\"ccc\"]}}}}",
                toJson(QueryBuilders.boolQuery().filter(q4).mustNot(q5)));

    }