我试图通过ElasticSearch发送一个bool查询,它会过滤掉一些文档。在Java中使用BooleanQueryBuilder Api,如何过滤布尔表达式(A AND B AND C) AND (D OR E OR F) AND G? 我已经尝试使用filter方法,但是没有返回结果。例如:
假设A、B、C、D、E、F、G都是事件,这些事件的属性"name"必须与"Robin"匹配。
private QueryBuilder getQueryBuilder() {
BoolQueryBuilder boolQueryBuilder1 = QueryBuilders
.boolQuery()
.filter(QueryBuilders.matchQuery(D).operator(Operator.OR))
.filter(QueryBuilders.matchQuery(E).operator(Operator.OR))
.filter(F);
BoolQueryBuilder boolQueryBuilder2 = QueryBuilders
.boolQuery()
.filter(QueryBuilders.matchQuery(A).operator(Operator.AND))
.filter(QueryBuilders.matchQuery(B).operator(Operator.AND))
.filter(QueryBuilders.matchQuery(C));
BoolQueryBuilder boolQueryBuilder3 = QueryBuilders
.boolQuery()
.filter(G);
BoolQueryBuilder boolQueryBuilder = QueryBuilders
.boolQuery()
.filter(boolQueryBuilder1)
.filter(boolQueryBuilder2)
.filter(boolQueryBuilder3);
return boolQueryBuilder;
}
我知道这个例子不是很好,但希望你能帮助我!谢谢!