Elasticsearch中的复杂bool查询

时间:2016-02-10 05:13:25

标签: elasticsearch full-text-search

如何为这种匹配构建查询?

(name="Adam" OR name="Bob) OR (age=21 && email="email@gmail.com")

如何将括号中的表达式与 OR 操作

“合并”
BoolQueryBuilder queryBuilder1 = QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery("name","Adam"))
.should(QueryBuilders.matchQuery("name","Bob"));

BoolQueryBuilder queryBuilder2 = QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("age","21"))
.must(QueryBuilders.matchQuery("email","email@gmail.com"));

1 个答案:

答案 0 :(得分:1)

您可以使用

BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery().should(queryBuilder1).should(queryBuilder2)

这将作为两个QueryBuilders

之间或之间的行为