模糊查询
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);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)