SELECT *
FROM your_table
WHERE
(xx = 'qw' AND yy = 'zz')
OR
(xx = 'zz' AND yy = 'qw');
上面SQL换成对应的ES 查询:
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery()
.should(
QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("xx", qw))
.must(QueryBuilders.termQuery("yy", zz))
)
.should(
QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("xx", zz))
.must(QueryBuilders.termQuery("yy", qw))
);
searchSourceBuilder.query(boolQueryBuilder);