java Elasticsearch or and 同时使用

java Elasticsearch or and 同时使用,第1张

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);

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/905846.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-15
下一篇 2022-05-15

发表评论

登录后才能评论

评论列表(0条)

保存