如何建立这种匹配的查询?

(name="Adam" OR name="Bob) OR (age=21 && email="[email protected]")

如何使用和操作“合并”括号中的表达式
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 protected]"));

最佳答案

您可以使用

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

这将充当两个QueryBuilders之间的代码

关于elasticsearch - Elasticsearch中的复杂 bool 查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35307315/

10-12 07:25