java Elasticsearch QueryBuilders 用法

java Elasticsearch QueryBuilders 用法,第1张

模糊查询



BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();

//Elasticsearch 中文会把汉字分词,“王大”会匹配到like“王”和like“大”,要在字段后面接keyword
boolBuilder.must(QueryBuilders.wildcardQuery("userName.keyword","*王大*"));

等于、不等于



BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
//等于  must
boolBuilder.must(QueryBuilders.termQuery("age","30"));
//不等于  mustNot
boolBuilder.mustNot(QueryBuilders.termQuery("sex","1"));

大于、小于



BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
//大于
boolBuilder.must(QueryBuilders.rangeQuery("createTime").gt(1609430400000));
//小于
boolBuilder.must(QueryBuilders.rangeQuery("createTime").lt(1672502400000));

 and 、or 同时使用  查看

where in条件



BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();

boolBuilder.filter(QueryBuilders.termsQuery("type",[1,2,3]));

排序


SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
//where 条件
searchSourceBuilder.query(boolBuilder);

//排序  SortOrder.ASC   SortOrder.DESC
searchSourceBuilder.sort("createTime", SortOrder.ASC);

 

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存