Elasticsearch想实现下面这个sql
select * from user where a=1 and ((b=2 and c=3 and d !=4) or (e=4 and f=5))
java Elasticsearch 实现
BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
boolBuilder.must(QueryBuilders.termQuery("a",1));
QueryBuilder queryBuilder1 = QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("b", 2))
.must(QueryBuilders.termQuery("c", 3))
.mustNot(QueryBuilders.termQuery("d", 4));
QueryBuilder queryBuilder2 = QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("e", 4))
.must(QueryBuilders.termQuery("f", 5));
QueryBuilder queryBuilder = QueryBuilders.boolQuery()
.should(queryBuilder1)
.should(queryBuilder2);
boolBuilder.must(queryBuilder);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)