假设我们可以将("name"="A" AND "name!="B")匹配为

BoolQueryBuilder queryBuilder1 = QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("name","A"))
.mustNot(QueryBuilders.matchQuery("name","B"));

我如何暗示对("name"="A" OR "name"!="B")进行“shouldNot”操作

喜欢,
BoolQueryBuilder queryBuilder1 = QueryBuilders.boolQuery()
    .should(QueryBuilders.matchQuery("name","A"))
    .sholdNot(QueryBuilders.matchQuery("name","B"));  // This API not exists..!

最佳答案

您可以使用此:

BoolQueryBuilder queryBuilder1 = QueryBuilders.boolQuery()
            .should(QueryBuilders.matchQuery("name","A"))
            .should(QueryBuilders.boolQuery()
            .mustNot(QueryBuilders.matchQuery("name","B")))

10-08 16:32